JENKINS UNDERGROUND – Build Triggers – PART 5

Build Triggers

So far we have been triggering the build using 2 ways:

  • Manually
  • By setting up a downstream job(which has an automatic trigger)

Let’s trigger the build remotely

Copied the URL

The url created to trigger the job will be as below:

http://18.216.155.253:8080/job/projectname/build?token=alphatoken

Let’s hit the url and see the result

Build has been Triggered

But there is one major issue in this. Here we have used the same browser, which was having our credentials saved for jenkins. If we try to trigger it from some remote laptop, it will ask for our jenkins credentials.

So as to tackle this scenario we will generate a token for admins user.

admin:xxxxxxx<token>

Next step is to Generate a Crumb

Execute the below command now:

wget -q --auth-no-challenge --user admin --password admin123 --output-document - 'http://18.216.155.253:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
Above command returns a crumb

Now we have 3 details:

  • The url created
  • The API token generated
  • Jenkins Crumb

Now we will use all these 3 things in a curl command to execute the build job from anywhere.

curl -I -X POST http://username:APIToken @Jenkins_IP:8080/job/Job_Name/build?token=TOKENNAME -H "Jenkins-Crumb:CRUMB"
I am able to trigger the build from remote now

Till now we have seen 3 ways to trigger the job. Let’s see another one.

This is used to set up an upstream job
Step 5: Build periodically using cron
Step 6: This will trigger the job on every commit

About the author

Deepak Sood

Deepak Sood is Lead Consultant in an IT firm holding expertise in Devops and QA Architecture with 8 years of experience.

His expertise is in building highly scalable frameworks. His skills include Java, Configuration Management, Containers, and Kubernetes.

Reach out to him using contact form.

View all posts