jac*_*ses 17 git docker github-actions
我正在 GitHub 中创建一个工作流,它创建并使用一个 docker 图像。因此,我使用此 docker 映像的全局环境变量启动了我的工作流文件,该环境变量对我的工作流中的所有作业都可见:
name: continuous integration
on:
push:
branches:
- '**'
env:
IMAGE: docker.pkg.github.com/${{ github.repository }}/jactor-persistence:${{ github.sha }}
Run Code Online (Sandbox Code Playgroud)
我想${{ github.sha }}
用head commit的short sha替换,和下面命令的结果一样git rev-parse --short HEAD
这可能吗?
pet*_*ans 23
正如 VonC 所提到的,您可以在上一步中自己计算字符串。
- name: Set outputs
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Check outputs
run: echo ${{ steps.vars.outputs.sha_short }}
Run Code Online (Sandbox Code Playgroud)
Lar*_*mel 13
You can also set an environment variable with the short sha:
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
Run Code Online (Sandbox Code Playgroud)
SHORT_SHA
can then be used like any other environment variable, e.g. like this:
- name: My step
run: myscript ${SHORT_SHA}
Run Code Online (Sandbox Code Playgroud)
这适用于 Windows:
- name: Get short SHA
run: echo "SHORT_SHA=$("${{ github.sha }}".SubString(0, 8))" >> $env:GITHUB_ENV
- name: Print short SHA
run: echo "Short SHA is ${{ env.SHORT_SHA }}"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13565 次 |
最近记录: |