英文:
Github-Action : Set Job environment only when condition true
问题
你是否可以在仅当满足定义的条件时才设置作业的“环境”?例如,仅当它作为INPUT传递时?
我的用例是:我正在使用可重用的工作流程,只有在将环境传递给工作流程时才想添加它。
environment 不接受null/false,只接受字符串或对象。
将输入的默认值设置为空字符串并在其他调用中设置为“example”是否有效?将其设置为空字符串的后果是什么?
参考:https://docs.github.com/en/actions/using-jobs/using-environments-for-jobs
英文:
Is it possible to set the "environment" of a job only if a defined condition is true ? So for example only if it was passed as INPUT ?
jobs:
test_workflow:
runs-on: ubuntu-latest
environment: EXAMPLE <-- This one
steps:
- uses: actions/checkout@v3
My use case: Im using a reusable_workflow and i only want to add the environment if it was passed to the workflow.
environment does not accept null/false but only string or object.
Would it work to set the default of the input to an empty string and to "example" in the other call ? What is the consequence of setting it to an empty string ?
Ref : https://docs.github.com/en/actions/using-jobs/using-environments-for-jobs
答案1
得分: 1
以下是翻译好的部分:
SOLUTION:
可以将ENVIRONMENT设置为空字符串,它将被视为未设置。
因此,我使用空字符串默认值定义了我的INPUT,只在需要时传递一个值!。
ENVIRONMENT:
type: string
default: ""
英文:
SOLUTION:
It is possible to set the ENVIRONMENT to an empty string and it will be treated like its not set.
So i defined my INPUT with the empty string default and only pass a value if needed!.
ENVIRONMENT:
type: string
default: ""
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论