英文:
Define list of elements in a GitHub Action variable
问题
自从几周前 GitHub 引入了必需的工作流和配置变量后,现在我想定义一个全局的 GitHub Actions 工作流,其中使用的变量不是简单的文本字符串,而是一个元素列表。
TEST_OS_VERSION = ''"ubuntu", "ubuntu-20.04"''
os: [${{ vars.TEST_OS_VERSIONS }}]
似乎 GitHub 不喜欢这样 :-/
我已经尝试过 TEST_OS_VERSION = ''["ubuntu", "ubuntu-20.04"]''
和 os: ${{vars.TEST_OS_VERSIONS }}
,但 GitHub 似乎也不喜欢它。
有没有关于如何存储一个包含元素的列表以在 GitHub 中使用的想法?
英文:
Since a few weeks GitHub introduced required workflows and configuration variables.
Now I want to define a global GitHub Actions workflow that uses a variable that is not a simple string of text, but a list of elements.
TEST_OS_VERSION = '"ubuntu", "ubuntu-20.04"'
os: [${{ vars.TEST_OS_VERSIONS }}]
Seems that GitHub does not like that :-/
I already tried TEST_OS_VERSION = '["ubuntu", "ubuntu-20.04"]'
and os: ${{vars.TEST_OS_VERSIONS }}
but again GitHub does not like it either.
Any idea on how to store in a variable a list of elements to be used in GitHub?
答案1
得分: 1
"fromJSON" 是解决方案,如 @jonrsharpe 所提到的从此处获取:
变量:["ubuntu", "ubuntu-20.04"]
yaml:os: ${{ fromJSON(vars.TEST_OS_VERSIONS) }}
英文:
As already mentions @jonrsharpe fromJSON is the solution:
Variable: ["ubuntu", "ubuntu-20.04"]
yaml: os: ${{ fromJSON(vars.TEST_OS_VERSIONS) }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论