Skip to content

sbitio/trigger-jenkins-job

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

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 }}