How to get current branch within github actions

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

    I just made a simple test within GitHub Actions using a bash script:

    #!/bin/bash
    
    echo Reserved for REPO_NAME=${GITHUB_REPOSITORY##*/}
    echo GITHUB_REF=${GITHUB_REF}
    echo EXTRACT_GITHUB_REF=${GITHUB_REF##*/}
    echo EXTRACT_GITHUB_REF_HEADS=$(echo ${GITHUB_REF#refs/heads/})
    
    cd $REPO_NAME
    git checkout ${GITHUB_REF##*/}
    git checkout $(echo ${GITHUB_REF#refs/heads/})
    

    Here is screenshot of the output:

    So both ${GITHUB_REF##*/} and $(echo ${GITHUB_REF#refs/heads/}) are correct

提交回复
热议问题