How to get current branch within github actions

前端 未结 13 2100
-上瘾入骨i
-上瘾入骨i 2020-11-29 20:11

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/f

13条回答
  •  星月不相逢
    2020-11-29 20:58

    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 }}
    

提交回复
热议问题