[英]If condition in Github Actions for another Job
My use case is, to trigger docs build when there is a trigger word in Pull Request Comments.我的用例是,当 Pull Request Comments 中有触发词时触发文档构建。 I am using pull-request-comment-trigger to know if a Trigger word is present in the code.我正在使用pull-request-comment-trigger来了解代码中是否存在触发词。
After knowing Action is triggered, I want to run some commands inside the repo.在知道触发了 Action 之后,我想在 repo 中运行一些命令。 So, I have to use actions/checkout for that.所以,我必须为此使用操作/结帐。
My doubt is, inside the run
command, Only Shell Commands are valid, Right?我的疑问是,在run
命令中,只有 Shell 命令有效,对吧? I want to run another job if above condition satisfies.如果上述条件满足,我想再做一份工作。
My Current Yaml File我当前的 Yaml 文件
name: Testing GH Actions
on:
pull_request:
types: [opened]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: khan/pull-request-comment-trigger@master
id: check
with:
trigger: "AppajiC"
reaction: rocket
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- run:
# Generally Anything here runs if below condition satisfies.
# I want to run another job here, which uses actions/checkout@v2 action
if: steps.check.outputs.triggered == 'true'
How can I achieve this?我怎样才能做到这一点?
You can use the condition for your checkout step and the following steps:您可以将条件用于结帐步骤和以下步骤:
- name: Checkout
uses: actions/checkout@v2
if: steps.check.outputs.triggered == 'true'
- name: Following step1
if: steps.check.outputs.triggered == 'true'
...
Alternatively, you can create a new job and use that if condition once:或者,您可以创建一个新作业并使用该 if 条件一次:
jobs:
deploy:
runs-on: ubuntu-latest
outputs:
deploy-status: ${{ steps.check.outputs.triggered }}
steps:
- uses: khan/pull-request-comment-trigger@master
id: check
with:
trigger: 'AppajiC'
reaction: rocket
env:
GITHUB_TOKEN: ${{ github.token }}
# this job will only run if steps.check.outputs.triggered == 'true'
# you just need to write the if once
after-deploy:
runs-on: ubuntu-latest
needs: [deploy]
if: needs.deploy.outputs.deploy-status == 'true'
steps:
- name: Checkout
uses: actions/checkout@v2
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.