HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to not "fire and forget" when doing a remote trigger of a Jenkins build?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
triggerjenkinsbuilddoingfireforgethowandnotwhen

Problem

I am attempting to trigger a parameterized Jenkins build from Bamboo, doing the below:


POST -
http://jenkins-url.com/job/jobname/buildWithParameters?ENVIRONMENT=dev&APPLICATION=hello-world

But I will get a 201 instantly which tells me that the build was created. How do I make this request wait and return the success status of the build instead of the fire and forget?

It is apparently possible as per Parameterized-Remote-Trigger-Plugin:

Edit:
created this in the end if you need it.
https://github.com/owenmorgan/jenkins-remote-builder

Solution

I've created the jenkins-remote-builder script which will follow your remote build to completion.

Some more details about it (from its README.md):

Example

jenkins=https://user:pass@jenkins.mydomain.com:8080
jenkins_job=MyApp-Deploy

environment=dev
application=myapp
revision=9fd71f63b351b8208264daf86d292ced580a2f60

./jenkins_remote_trigger.sh \
            -h ${jenkins} \
            -j ${jenkins_job} \
            -p "ENVIRONMENT=${environment}&APPLICATION=${application}&REVISION=${revision}"


Usage:

-h HOST     | --host=HOST                       Jenkins host
-j JOBNAME  | --jobname=test-build-job          The name of the jenkins job to trigger
-p JOBPARAM | --jobparam=environment=uat&test=1 Jenkins job paramiters
-q          | --quiet                           Don't output any status messages

Code Snippets

jenkins=https://user:pass@jenkins.mydomain.com:8080
jenkins_job=MyApp-Deploy

environment=dev
application=myapp
revision=9fd71f63b351b8208264daf86d292ced580a2f60

./jenkins_remote_trigger.sh \
            -h ${jenkins} \
            -j ${jenkins_job} \
            -p "ENVIRONMENT=${environment}&APPLICATION=${application}&REVISION=${revision}"
-h HOST     | --host=HOST                       Jenkins host
-j JOBNAME  | --jobname=test-build-job          The name of the jenkins job to trigger
-p JOBPARAM | --jobparam=environment=uat&test=1 Jenkins job paramiters
-q          | --quiet                           Don't output any status messages

Context

StackExchange DevOps Q#457, answer score: 6

Revisions (0)

No revisions yet.