Github-Action:仅在条件为真时设置作业环境

huangapple go评论60阅读模式
英文:

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: ""

huangapple
  • 本文由 发表于 2023年6月26日 21:53:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557341.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定