Getting current branch and commit hash in GitHub action

前端 未结 5 2331
生来不讨喜
生来不讨喜 2021-02-19 05:26

I want to build a docker image using a GitHub action, migrating from TeamCity.

In the build script, I want to tag the image with a combination of branch and commit, e.g.

5条回答
  •  孤独总比滥情好
    2021-02-19 05:57

    You can get it this way in your sh file -

    BRANCH_NAME=$(echo $GITHUB_REF | cut -d'/' -f 3)
    GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c1-8)
    

提交回复
热议问题