9

My use case is, to trigger docs build when there is a trigger word in Pull Request Comments. I am using pull-request-comment-trigger to know if a Trigger word is present in the code.

After knowing Action is triggered, I want to run some commands inside the repo. So, I have to use actions/checkout for that.

My doubt is, inside the run command, Only Shell Commands are valid, Right? I want to run another job if above condition satisfies.

My Current Yaml File

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 ?

2
  • You can use the same if condition in your checkout step. Alternatively, you can create a new job that has that if condition for the entire job, so you don't need to repeat the if for every step.
    – soltex
    Commented Mar 21, 2021 at 11:48
  • Could you please give a example snippet? Commented Mar 21, 2021 at 12:21

1 Answer 1

23

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:

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
        
      ...
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.