How to get current branch within github actions

前端 未结 13 2073
-上瘾入骨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 21:00

    The GitHub Action FranzDiebold/github-env-vars-action exposes several useful environment variables, such as current branch name and their slug values. I made this action exactly for this use case.

    Usage

    steps:
      - uses: FranzDiebold/github-env-vars-action@v1.2.0
      - name: Print environment variables
        run: |
          echo "GITHUB_REPOSITORY_SLUG=$GITHUB_REPOSITORY_SLUG"
          echo "GITHUB_REPOSITORY_OWNER=$GITHUB_REPOSITORY_OWNER"
          echo "GITHUB_REPOSITORY_OWNER_SLUG=$GITHUB_REPOSITORY_OWNER_SLUG"
          echo "GITHUB_REPOSITORY_NAME=$GITHUB_REPOSITORY_NAME"
          echo "GITHUB_REPOSITORY_NAME_SLUG=$GITHUB_REPOSITORY_NAME_SLUG"
          echo "GITHUB_REF_SLUG=$GITHUB_REF_SLUG"
          echo "GITHUB_REF_NAME=$GITHUB_REF_NAME"
          echo "GITHUB_REF_NAME_SLUG=$GITHUB_REF_NAME_SLUG"
          echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT"
    

    A demo for all Operating systems (Linux, macOS and Windows) is also available in the demo workflows file of the repository!

提交回复
热议问题