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

后端 未结 1 387
独厮守ぢ
独厮守ぢ 2020-12-05 06:31

In GitHub Actions, I\'d like to evaluate a bash expression and then assign it to an environment variable:

    - name         


        
相关标签:
1条回答
  • 2020-12-05 07:23

    The original answer to this question used the Actions runner function set-env. Due to a security vulnerability set-env is being deprecated and should no longer be used.

    This is the new way to set environment variables.

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

    Setting an environment variable echo "{name}={value}" >> $GITHUB_ENV

    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/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable)

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

        - name: Test
          run: echo ${{ env.GITHUB_SHA_SHORT }}
    
    0 讨论(0)
提交回复
热议问题