我希望使用GitHub action构建Docker镜像,从TeamCity迁移而来。
在构建脚本中,我想要使用分支和提交的组合来标记镜像,例如master.ad959de
。在本地测试时,我可以通过以下方式获取这些信息:
git_branch=`git symbolic-ref --short HEAD`
git_hash=`git rev-parse --short HEAD`
docker_version=${git_branch}.${git_hash}
这是 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
在 GitHub action 中运行该脚本会导致以下错误:
fatal: ref HEAD is not a symbolic ref
我该如何在GitHub action中生成这样的标签?