Github Action use environment variable as port

580 Views Asked by At

How can I use the global environment variable (that I set at the top of the file) as my port number in Github Action (.yml config file)? Is this possible?

I have tried

env: 
   APP_PORT: 3306

   ......
   services: 
     mysql:
   ....
       ports:
       - ${{ env.APP_PORT }}
1

There are 1 best solutions below

1
On

What you are trying to do is not possible, as services are defined below a job and not below a step:

You can use the env context in the value of any key in a step except for the id and uses keys.

source: https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#env-context)