GitHub Actions 中工作流程和作业之间的环境变量。

huangapple go评论61阅读模式
英文:

environment variables between workflow and job for github actions

问题

我正在创建工作流程:
在工作流和任务之间设置环境变量:
访问基于工作流的环境时,我遇到错误:

无法识别的命名值:'env'。位于表达式内的位置1:env.ACCOUNT_ID

我只想访问基于作业的环境,同时引用基于工作流的环境。

工作流程

env:
 AWS_REGION: ${{ vars.AWS_REGION }}
 ACCOUNT_ID: ${{ secrets.TRAINING_ACCOUNT_ID }}

jobs:
 dev:
    runs-on: ubuntu-latest
    env:
      ECR_REGISTRY: ${{ env.ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com
  steps:
   - name: build
     run: |
       aws --region ${{ env.AWS_REGION }} ecr get-login-password | docker login --username AWS --password-stdin ${{ env.ECR_REGISTRY }}
英文:

I'm creating workflow:
where environment variables are sets between workflow and jobs:
While accessing the workflow based env, I'm getting error:

Unrecognized named-value: 'env'. Located at position 1 within expression: env.ACCOUNT_ID

all I want to access the job based env to each steps while referring to workflow based env.

The workflow

env:
 AWS_REGION: ${{ vars.AWS_REGION }}
 ACCOUNT_ID: ${{ secrets.TRAINING_ACCOUNT_ID }}

jobs:
 dev:
       runs-on: ubuntu-latest
    env:
      ECR_REGISTRY: ${{ env.ACCOUNT_ID }}.dkr.ecr.${{env.AWS_REGION}}.amazonaws.com
  steps:
   - name: build
     run: |
       aws --region ${{env.AWS_REGION}} ecr get-login-password | docker login --username AWS --password-stdin ${{env.ECR_REGISTRY}}

答案1

得分: 1

I found this as answer after a quite trial, if someone has the official answer, please post it.
But to work in my case, this is the hack:

env:
 AWS_REGION: ${{ vars.AWS_REGION }}
 ACCOUNT_ID: ${{ secrets.TRAINING_ACCOUNT_ID }}

jobs:
 dev:
       runs-on: ubuntu-latest
    env:
      ECR_REGISTRY: $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
  steps:
   - name: build
     run: |
       aws --region ${{env.AWS_REGION}} ecr get-login-password | docker login --username AWS --password-stdin ${{env.ECR_REGISTRY}}
英文:

I found this as answer after a quite trial, if someone has the official answer, please post it.
But to work in my case, this is the hack:

env:
 AWS_REGION: ${{ vars.AWS_REGION }}
 ACCOUNT_ID: ${{ secrets.TRAINING_ACCOUNT_ID }}

jobs:
 dev:
       runs-on: ubuntu-latest
    env:
      ECR_REGISTRY: $ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
  steps:
   - name: build
     run: |
       aws --region ${{env.AWS_REGION}} ecr get-login-password | docker login --username AWS --password-stdin ${{env.ECR_REGISTRY}}

huangapple
  • 本文由 发表于 2023年2月6日 18:14:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359938.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定