Skip to content
sun

GitHub Action

Trigger a Jenkins Job

v1.3 Latest version

Trigger a Jenkins Job

sun

Trigger a Jenkins Job

GitHub action that triggers a Jenkins Job

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Trigger a Jenkins Job

uses: sbitio/trigger-jenkins-job@v1.3

Learn more about this action in sbitio/trigger-jenkins-job

Choose a version

Trigger jenkins job action

This action triggers a given Jenkins job when called

Inputs

'JENKINS_USER'

Required The name of the jenkins user that will trigger the Jenkins job (The user must have the neccessary permissions).

'JENKINS_TOKEN'

Required Jenkins API token. Follow these instructions to generate a token for the jenkins user that will trigger the job: https://www.jenkins.io/blog/2018/07/02/new-api-token-system/.

Important JENKINS_USER and JENKINS_TOKEN should be declared in repository secrets for security purposes. The rest of the variables can be declared as envs.

'JENKINS_HOST'

Required Jenkins base url.

'JENKINS_JOB'

Required Jenkins job location that will be built. Ex: JENKINS_JOB = utils/testPipeline/helloWorld makes reference to the helloWorld job inside the utils/testPipeline/ directory.

'JENKINS_PARAMS'

Optional Parameters to be passed to the jenkins jobs if they are required. they must be written in this format: param=value. If there is more than one parameter, they must be sparated by & (Example: param1=value1&param2=value2 ). If the job has no defined parameters then JENKINS_PARAMS must be given the value no, and if the job does have parameters but you want to use the default values then the input can be left empty.

Example usage

Example usage of the action. This workflow triggers a Jenkins job when a change is pushed to the repository.

on: push

jobs:
  launch_jenkins_job:
    name: trigger jenkins job
    runs-on: ubuntu-latest
    steps:
      -
        name: Trigger Jenkins Job
        uses: sbitio/trigger-jenkins-job@master
        with:
          JENKINS_USER: ${{ secrets.JENKINS_USER }}
          JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
          JENKINS_HOST: ${{ secrets.JENKINS_HOST }}
          JENKINS_JOB: ${{ secrets.JENKINS_JOB }}

Example usage of the action to trigger a parametized job.

on: push

env:
  JENKINS_HOST: https://jenkins.example.com/ ## jenkins base url
  JENKINS_JOB: testJobs/HelloWorld ## builds the HelloWorld job inside testJobs
  JENKINS_PARAMS: environment=dev

jobs:
  launch_jenkins_job:
    name: trigger jenkins job
    runs-on: ubuntu-latest
    steps:
      -
        name: Trigger Jenkins Job
        uses: sbitio/trigger-jenkins-job@master
        with:
          JENKINS_USER: ${{ secrets.JENKINS_USER }}
          JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
          JENKINS_HOST: ${{ env.JENKINS_HOST }}
          JENKINS_JOB: ${{ env.JENKINS_JOB }}
          JENKINS_PARAMS: ${{ env.JENKINS_PARAMS }}

Example usage of the action to trigger a unparametized job.

on: push

env:
  JENKINS_HOST: https://jenkins.example.com/ ## jenkins base url
  JENKINS_JOB: testJobs/HelloWorld ## builds the HelloWorld job inside testJobs
  JENKINS_PARAMS: no

jobs:
  launch_jenkins_job:
    name: trigger jenkins job
    runs-on: ubuntu-latest
    steps:
      -
        name: Trigger Jenkins Job
        uses: sbitio/trigger-jenkins-job@master
        with:
          JENKINS_USER: ${{ secrets.JENKINS_USER }}
          JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
          JENKINS_HOST: ${{ env.JENKINS_HOST }}
          JENKINS_JOB: ${{ env.JENKINS_JOB }}
          JENKINS_PARAMS: ${{ env.JENKINS_PARAMS }}