Github Action使用环境变量作为端口

时间:2020-09-29 19:08:47

标签: github continuous-integration github-actions

如何在Github Action(.yml配置文件)中将全局环境变量(在文件顶部设置的)用作端口号?这可能吗?

我尝试过

env: 
   APP_PORT: 3306

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

1 个答案:

答案 0 :(得分:0)

访问表达式中的环境变量需要使用env.前缀(另请参见https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#env-context):

env: 
   APP_PORT: 3306

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