Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Pilot Lvl 1
Message 1 of 6

Job environment can't access services

Solved! Go to Solution.

I was happy to know that the global environment is now alive and can be within the job or the workflow (https://github.blog/changelog/2019-10-01-github-actions-new-workflow-syntax-features/#env-at-the-wor...)

but for some reason, the env at the job level can't access any information about the services, for example, something like the following

 

name: CI
on: [push, pull_request]
jobs:
  phpunit:
    name: PHPUnit
    runs-on: ubuntu-latest
    env:
      DB_PORT: ${{ job.services.mysql.ports['3306'] }}
      DB_PASSWORD: password
      BROADCAST_DRIVER: log
      CACHE_DRIVER: redis
      QUEUE_CONNECTION: redis
      SESSION_DRIVER: redis    
    services:
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: false
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: laravel
        ports:
          - 3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

Will not work, neither

 

jobs:
  phpunit:
    name: PHPUnit
    runs-on: ubuntu-latest
    env:
      DB_PORT: ${{ services.mysql.ports['3306'] }}
      DB_PASSWORD: password
      BROADCAST_DRIVER: log
      CACHE_DRIVER: redis
      QUEUE_CONNECTION: redis
      SESSION_DRIVER: redis   

The error I get back:

 

Your workflow file was invalid: The pipeline is not valid. .github/workflows/ci.yml (Line: 26, Col: 16): Unrecognized named-value: 'job'. Located at position 1 within expression: job.services.mysql.ports['3306']

 

Any idea how to fix that, other than moving the env to the task that need to connect to the database? or it is by design?

 

 

------------------------

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

5 Replies
Solution
GitHub Staff
Message 2 of 6

Re: Job environment can't access services

That is currently by design.  The job level ENV is built before the services are setup on the runner so those values are not known.   Your only option is to pass the variable to the step where it is needed.

Highlighted
Pilot Lvl 1
Message 3 of 6

Re: Job environment can't access services

hey @chrispat  is there any plan to change this behavior?

------------------------

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

GitHub Staff
Message 4 of 6

Re: Job environment can't access services

Not at the moment.  We will continue to evaluate based on feedback.

Pilot Lvl 1
Message 5 of 6

Re: Job environment can't access services

Thank you very much 👍

 

 

 

------------------------

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 6 of 6

Re: Job environment can't access services

@chrispatI've also run into this issue and would love to be able to do what @linuxjuggler suggests.  I have multiple steps that require the database port value.