如何在github动作中获取当前分支 [英] How to get current branch within github actions

查看:89
本文介绍了如何在github动作中获取当前分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Github Actions构建docker映像,并想用分支名称标记映像, 我只找到了GITHUB_REF变量,但是它导致了refs/heads/feature-branch-1,而我只需要feature-branch-1.

I'm building docker images with Github Actions and want to tags images with branch name, I found only 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动作中获取当前分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆