相关疑难解决方法(0)

Getting current branch and commit hash in GitHub action

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. master.ad959de. Testing that locally, I get that information like this:

git_branch=`git symbolic-ref --short HEAD`
git_hash=`git rev-parse --short HEAD`
docker_version=${git_branch}.${git_hash}
Run Code Online (Sandbox Code Playgroud)

This is the relevant part of the GitHub action:

name: CI
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1

    - name: Create docker image
      run: ./docker-build.sh …
Run Code Online (Sandbox Code Playgroud)

git github github-actions

26
推荐指数
4
解决办法
3万
查看次数

标签 统计

git ×1

github ×1

github-actions ×1