【问题标题】:GitHub Action to build environment variables from each otherGitHub Action 相互构建环境变量
【发布时间】:2021-09-24 22:23:47
【问题描述】:

在GitHub Action中,如何依次构建环境变量:

name: workflow-level-custom-environment-variables

on: [push]
# Here the environment variable is declared in workflow level
env:
    PART1: var1
    PART2: ${PART1}var2
    PUBLICENV: ${PART2} Available for all jobs in this workflow

这真的很有用,例如,这是一个来自 Dockerfile 的真实示例:

ARG JMETER_VERSION="5.4.2"
ENV JMETER_HOME /opt/apache-jmeter-${JMETER_VERSION}

我知道Dockerfile 不是 GitHub Action,但我只是展示它有用的原理。

【问题讨论】:

  • 不,我自己没有尝试过解决方案。但我在 github action 的文档中读到了它。这里:docs.github.com/en/actions/reference/environment-variables
  • 是否必须在工作流级别?因为您可以在步骤级别将>> $GITHUB_ENV 与shell 命令一起使用(这会更容易)。
  • @GuiFalourd,是的,我认为这可能是唯一的选择,因为我发现的“解决方案”就是这样做的——brandur.org/fragments/github-actions-env-vars-in-env-vars,它要求不同的分配需要不同我试图避免的步骤。

标签: environment-variables github-actions


【解决方案1】:

@xpt 我为此目的构建了一个 github 操作,您可以在其中将变量和范围替换和组合到特定环境。也许对你的场景有一些用处 -> https://github.com/jnus/json-variables

【讨论】:

  • 这看起来很有希望,但目前我只想使用环境变量,而不是任何 json 文件。不过感谢您的信息!
猜你喜欢
  • 1970-01-01
  • 2020-12-10
  • 2021-10-08
  • 1970-01-01
  • 2021-06-19
  • 1970-01-01
  • 2021-12-06
  • 2020-10-29
  • 2020-05-09
相关资源
最近更新 更多