【发布时间】:2021-09-19 20:11:36
【问题描述】:
我一直在尝试在 Github 操作中构建 CICD 管道,但我们无法同时处理 if 和 or 条件。下面是我们代码sn-p的例子,
name: Build Non prod
needs: [rules]
if: ${{ (needs.rules.outputs.branch_name != 'production') || (needs.rules.outputs.branch_name != 'staging') }}
steps:
- name: Checkout
uses: actions/checkout@v2
因此,此任务不应在 production 和 staging 分支中运行,但当操作在 staging 分支中运行时,此作业也会与其他不适用于 staging 环境的作业一起触发。
有什么方法可以让我们拥有if 和or 条件?
更新:
条件无效,以下更新的条件将有效。
if: ${{ (needs.rules.outputs.branch_name != 'production') && (needs.rules.outputs.branch_name != 'staging') }}
【问题讨论】:
-
你能分享你的
rules舞台/工作吗? -
嘿,问题解决了。必须使用以下条件才能使其无法在登台和生产环境中运行。因此,当它在 Development 或 QA 环境中时,它满足以下条件并且工作被跳过。
yaml if: ${{ (needs.rules.outputs.branch_name != 'production') && (needs.rules.outputs.branch_name != 'staging') }}当它在暂存或生产环境中时,代码 sn-p 将告诉操作运行而不是跳过yaml if: ${{ (needs.rules.outputs.branch_name != 'production') ||(needs.rules.outputs.branch_name != 'staging') }}
标签: github-actions cicd