我正在使用 Github Actions 构建 Docker 映像,并希望使用分支名称标记映像。
我找到了GITHUB_REF变量,但结果是refs/heads/feature-branch-1我只需要feature-branch-1.
GITHUB_REF
refs/heads/feature-branch-1
feature-branch-1
我添加了一个单独的步骤来从中提取分支名称$GITHUB_REF并将其设置为步骤输出
$GITHUB_REF
- name: Extract branch name shell: bash run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" id: extract_branch
之后,我可以在接下来的步骤中使用它
- name: Push to ECR id: ecr uses: jwalton/gh-ecr-push@master with: access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} region: us-west-2 image: eng:${{ steps.extract_branch.outputs.branch }}