在github操作中,我有一个if,但是如果我在else的情况下,我仍然需要运行一些其他的东西。有没有一种干净的方法来做这件事,或者我必须在false条件相同的情况下再做一步?
- if: contains(['SNAPSHOT'],env.BUILD_VERSION)
name:IF
run: echo ":)"
- if: false == contains(['SNAPSHOT'], env.BUILD_VERSION)
name: Else
run: echo ":("发布于 2020-04-08 15:53:09
GitHub操作没有else语句来运行不同的命令/操作/代码。但是你是对的,你所需要做的就是用反转的if条件创建另一个步骤。顺便说一句,你可以用!代替false ==。
以下是一些链接:if statement、operators
发布于 2021-02-09 05:44:28
您可以执行以下操作,这些操作将仅在条件通过的地方运行脚本:
job_name:
runs-on: windows-latest
if: "!contains(github.event.head_commit.message, 'SKIP SCRIPTS')" <--- skips everything in this job if head commit message does not contain 'SKIP SCRIPTS'
steps:
- uses: ....
- name: condition 1
if: "contains(github.event.head_commit.message, 'CONDITION 1 MSG')"
run: script for condition 1
- name: condition 2
if: "contains(github.event.head_commit.message, 'CONDITION 2 MSG')"
run: script for condition 2诸若此类。当然你会在这里使用你自己的条件。
发布于 2021-04-28 06:53:28
您可以考虑使用haya14busa/action-cond操作。当需要if-else操作来设置其他步骤的动态配置时(不需要重复整个步骤来在几个参数中设置不同的值),这是很有用的。
示例:
- name: Determine Checkout Depth
uses: haya14busa/action-cond@v1
id: fetchDepth
with:
cond: ${{ condition }}
if_true: '0' # string value
if_false: '1' # string value
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: ${{ steps.fetchDepth.outputs.value }}https://stackoverflow.com/questions/60916931
复制相似问题