How to get current branch within github actions

前端 未结 13 2072
-上瘾入骨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:45

    You could use https://github.com/rlespinasse/github-slug-action

    - name: Inject slug/short variables
      uses: rlespinasse/github-slug-action@v2.x
    
    - name: Print slug/short variables
      run: |
        echo "Slug variables"
        echo " - ${{ env.GITHUB_REF_SLUG }}"    
        echo " - ${{ env.GITHUB_HEAD_REF_SLUG }}"
        echo " - ${{ env.GITHUB_BASE_REF_SLUG }}"
        echo " - ${{ env.GITHUB_REPOSITORY_SLUG }}"
        // output e.g. : master feat-new-feature v1.0.0 product-1.0.0-rc.2 new-awesome-product
        echo "Slug URL variables"
        echo " - ${{ env.GITHUB_REF_SLUG_URL }}"
        echo " - ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
        echo " - ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
        echo " - ${{ env.GITHUB_REPOSITORY_SLUG_URL }}"
        // output e.g. : master feat-new-feature v1-0-0 product-1-0-0-rc-2 new-awesome-product
        echo "Short SHA variables"
        echo " - ${{ env.GITHUB_SHA_SHORT }}"
        // output e.g. : ffac537e
    

提交回复
热议问题