Trigger GitHub Actions from Jenkins Pipeline using API/Actions Pluginfor Jenkins

1.2k Views Asked by At

I want to trigger the GitHub Actions using Jenkins Pipeline or Jenkins Job and send some build parameters as input for the GitHub Actions. I am doing this since there is no option of dropdown list for the GitHub Action Input parameters.

3

There are 3 best solutions below

0
On

We can trigger Github action with rest api (POST) or curl requests. All you need to do create with workflow with dispatch trigger (repository_dispatch or workflow_dispatch)

on:
  workflow_dispatch:
    inputs:
      InputKey:
        type: string
        required: true

next trigger this workflow by one of the below methods

1. POST https://api.github.com/repos///dispatches Authorization: Bearer

{"event_type": "hello"}
  1. curl --request POST
    --url 'https://api.github.com/repos///dispatches'
    --header 'authorization: Bearer '
    --data '{"event_type": "hello"}'

Also specify the inputs in requests with --data '{"event_type": "<workflow name>","client_payload":{"<input_key>":"<input_value>"}}'

All you need to do now is put this request in your job (scripted pipeline is preferred) with appropriate values.

0
On

"We can use the POST Api call from jenkins to github to intimate and start github actions. Steps to follow:

  1. Create a webhook in github and configure jenkins url and events you want to trigger the github actions.
  2. In the github action you want to trigger after jenkins build, you need to add the following line. on:
 
  workflow_run:
    workflows: [""your_workflow_name""]
    types:
      - completed
  1. Configure the POST api call from jenkins to github along with the parameters you need to send.
0
On

This is only half a solution. But there is an option to specify an input params list for GitHub actions.

See workflow_dispatch event type on GitHub actions. The current url is here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch (If this stops working just google workflow_dispatch)

The other half (Jenkins triggering a GHA build), I am actually searching for myself too! I can find ones working in reverse. GHA triggering jenkins.