如何在 Github Actions 中获取当前分支?
·
问题:如何在 Github Actions 中获取当前分支?
我正在使用 Github Actions 构建 Docker 映像,并希望使用分支名称标记映像。
我找到了GITHUB_REF变量,但结果是refs/heads/feature-branch-1,我只需要feature-branch-1。
解答
我添加了一个单独的步骤,用于从$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 }}
更多推荐


所有评论(0)