How do i set an env var with a bash expression in GitHub Actions?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 02:27:19

问题


In GitHub Actions i'd like to evaluate a bash expression and then assign it to an environment variable -

    - name: Tag image
      env:
        GITHUB_SHA_SHORT: ${{ $(echo $GITHUB_SHA | cut -c 1-6) }}
      ..do other things...

However this naive attempt has failed. According to the docs this doesn't seem to be supported however a somewhat clean workaround would be fine.


回答1:


Using set-env in a previous step works for me.

name: my workflow
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Set env
      run: echo ::set-env name=GITHUB_SHA_SHORT::$(echo $GITHUB_SHA | cut -c 1-6)
    - name: Test
      run: echo $GITHUB_SHA_SHORT

Set an environment variable: set-env ::set-env name={name}::{value}

Creates or updates an environment variable for any actions running next in a job. The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access. Environment variables are case-sensitive and you can include punctuation.

(From https://help.github.com/en/articles/development-tools-for-github-actions#set-an-environment-variable-set-env)

This is an alternative way to reference the environment variable in workflows.

    - name: Test
      run: echo ${{ env.GITHUB_SHA_SHORT }}


来源:https://stackoverflow.com/questions/57968497/how-do-i-set-an-env-var-with-a-bash-expression-in-github-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!