如何在 Github Actions 中获取当前分支? [英] How to get the current branch within Github Actions?
本文介绍了如何在 Github Actions 中获取当前分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Github Actions 构建 Docker 镜像,并想用分支名称标记镜像.
I'm building Docker images with Github Actions and want to tag images with the branch name.
我找到了 GITHUB_REF
变量,但结果是 refs/heads/feature-branch-1
而我只需要 feature-branch-1
代码>.
I found the GITHUB_REF
variable, but it results in refs/heads/feature-branch-1
and I need only feature-branch-1
.
推荐答案
我添加了一个单独的步骤,用于从 $GITHUB_REF
中提取分支名称并将其设置为步骤输出
I added a separate step for extracting branch name from $GITHUB_REF
and set it to the step output
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
在那之后,我可以在接下来的步骤中使用它
after that, I can use it in the next steps with
- 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 }}
这篇关于如何在 Github Actions 中获取当前分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文