GitHub上的动作:env:在env部分的RHS上使用预定义的环境变量 [英] GitHub Actions: env: Use pre-defined environment variables on RHS within env section

查看:208
本文介绍了GitHub上的动作:env:在env部分的RHS上使用预定义的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 main.yml 的顶级 env 部分中声明一些环境变量,其值使用一些预定义的环境变量,例如记录在案的 .但是,看来我不能在我的env部分的右侧使用这些预定义的变量.例如:

I would like to declare some environment variables in a top level env section in my main.yml whose values use some pre-defined environment variables such as those documented in the GitHub Actions documentation. However, it appears I cannot use those pre-defined variables in the right hand side of my env section. For example:

env:
  resourceGroup: ${GITHUB_RUN_ID}${GITHUB_RUN_NUMBER}

有没有一种方法可以使需要$ {resourceGroup}的任何步骤都可以获取它,而不必在每个步骤中手动定义它?

Is there a way to make it so any step that needs ${resourceGroup} can get it without having to manually define it within each step?

推荐答案

我尝试了以下两种方法.

I tried the following two ways.

env:
  resourceGroup1: ${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}
  resourceGroup2: ${{ github.run_id }}-${{ github.run_number }}

jobs:
  foo:
    runs-on: ubuntu-latest
    steps:
      - name: test1
        run: echo ${{ env.resourceGroup1 }}
      - name: test2
        run: echo ${{ env.resourceGroup2 }}

在两种情况下,都可以正确获得结果.

In both cases, the results were obtained correctly.

但是,在结果为env的情况下,尚未对其进行评估.也许您可以使用后者.

However, in the case of env as a result, the former has not yet been evaluated. Maybe you can use the latter.

这篇关于GitHub上的动作:env:在env部分的RHS上使用预定义的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆