Github Actions是否有DRY方式在多个作业步骤中计算和共享值?
在下面的工作流程yml文件中,回显$ {GITHUB_REF} | cut -d'/'-f3`-$ {GITHUB_SHA}会分多个步骤重复。
name: Test, Build and Deploy
on:
push:
branches:
- master
jobs:
build_and_push:
name: Build and Push
runs-on: ubuntu-latest
steps:
- name: Docker Build
uses: "actions/docker/cli@master"
with:
args: build . --file Dockerfile -t cflynnus/blog:`echo ${GITHUB_REF} | cut -d'/' -f3`-${GITHUB_SHA}
- name: Docker Tag Latest
uses: "actions/docker/cli@master"
with:
args: tag cflynnus/blog:`echo ${GITHUB_REF} | cut -d'/' -f3`-${GITHUB_SHA} cflynnus/blog:latest
Run Code Online (Sandbox Code Playgroud) 在GitHub Actions中,我想评估bash表达式,然后将其分配给环境变量-
- name: Tag image
env:
GITHUB_SHA_SHORT: ${{ $(echo $GITHUB_SHA | cut -c 1-6) }}
..do other things...
Run Code Online (Sandbox Code Playgroud)
但是,这种幼稚的尝试失败了。根据文档,这似乎不受支持,但是稍微干净的解决方法就可以了。