This action triggers a given Jenkins job when called
Required The name of the jenkins user that will trigger the Jenkins job (The user must have the neccessary permissions).
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.
Required Jenkins base url.
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.
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¶m2=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 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 }}