How to manually trigger of a specific job in a workflow

Hi,

My GitHub Action gets triggered by a Commit to the master branch. See below -

Workflow file -
name: Mule Cloudhub-CI/CD (Prod)

on:
push:
branches: [ master ]

jobs:
build-package:
name: Build application package
runs-on: ubuntu-latest
steps:
- name: Clone working repository
uses: actions/checkout@v2
- name: Clone ‘mule-ci’ common repository
uses: actions/checkout@v2
with:
repository: city-of-whittlesea/mule-ci
token: {{ secrets.ACCESS_TOKEN }} path: mule-ci - name: Maven cache uses: actions/cache@v1 with: path: ~/.m2/repository key: {{ runner.os }}-maven-{{ hashFiles('**/pom.xml') }} restore-keys: {{ runner.os }}-maven-
- name: Run script for Maven build
run: . mule-ci/shell_scripts/build
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: mule-ci
path: mule-ci

uat-deploy:
needs: [build-package]
name: Deploy to UAT environment
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v1
with:
name: mule-ci
- name: Run script for UAT deployment
run: . mule-ci/shell_scripts/deploy uat
env:
CI_BUILD_PASSWORD: ${{ secrets.CI_BUILD_PASSWORD }}

prod-deploy:
needs: [uat-deploy]
name: Deploy to PROD environment
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v1
with:
name: mule-ci
- name: Run script for PROD deployment
run: . mule-ci/shell_scripts/deploy prod
env:
CI_BUILD_PASSWORD: ${{ secrets.CI_BUILD_PASSWORD }}

What I want is to trigger my “prod-deploy” manually as we can do in BitBucket.

To “Manually” trigger a workflow, you will need to add a workflow file in the default branch that listens to the workflow_dispatch event.

You can try something like this. (test with dev-deploy, prod-deploy as the input)

name: Manually triggered workflow
on:
  workflow_dispatch:
    inputs:
      job:
        description: 'Job to run.'
        required: true
        default: 'prod-deploy'
jobs:
  dev-deploy:
    name: Deploy dev-deploy
    runs-on: ubuntu-latest
    if: ${{ github.event.inputs.job == 'dev-deploy'}}
    steps:
    - name: ${{ github.event.inputs.job }} - step 1
      run: echo "${{ github.event.inputs.job }} triggered!"

  prod-deploy:
    name: Deploy prod-deploy
    runs-on: ubuntu-latest
    if: ${{ github.event.inputs.job == 'prod-deploy'}}
    steps:
    - name: ${{ github.event.inputs.job }} - step 1
      run: echo "${{ github.event.inputs.job }} triggered!"

Hope that helps… :v:t4:

Thanks a ton. Although it’s sort of a work around but should do my job well.