DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building Micro-Frontends With Vue and Reusable Components
  • Build an AI Chatroom With ChatGPT and ZK by Asking It How!
  • Build Your Own AI Avatar App From Scratch in Less Than 8 Hours
  • 10 Best Practices to Launch APIs in 2023

Trending

  • Improving DAG Failure Detection in Airflow Using AI Techniques
  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • From Data Movement to Local Intelligence: The Shift from Centralized to Federated AI
  • Throughput vs Goodput: The Performance Metric You Are Probably Ignoring in LLM Testing
  1. DZone
  2. Data Engineering
  3. Databases
  4. Triggering Jenkins Build Remotely Using API

Triggering Jenkins Build Remotely Using API

Any Jenkins Job can be triggered remotely through an API call. This article outlines how to do exactly that in just four easy steps.

By 
Shantha Priya user avatar
Shantha Priya
·
Apr. 10, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
29.1K Views

Join the DZone community and get the full member experience.

Join For Free

Any Jenkins Job can be triggered remotely through an API call.

We can extract the API output either in XML(SOAP) or in JSON(REST) format.

STEP 1: Get the Authorization Token

1.Click on the Configure option under your username

2.Under API token Click on the Show Legacy API Token. See images below.

 


 

3.Copy the token and use it in the place of a password

STEP 2: Trigger the Build

API: https://JENKINS_URL/job_path/buildwithParemters?

Method: POST

Parameters: Username= “username” 

Password= “Token”

OUTPUT: 

Return the header with the queue number of the job.

The above two steps are used to trigger a Jenkins Parameterized build remotely. In order to get the status of the build, you must follow the three steps below. Jenkins build, once triggered, will have the below flow:

Job Triggered->Waits on Queue(Queue Number)->assign node for the build -> gets a Build Number

STEP 3: Get the Build Number

Pass the Location URL from the previous API output header to get the Build Number.

API: Locationurl/api/json?

 Eg: https://jenkins.xxx.com/jenkins/queue/item/1691997/api/json

Method: GET 

Parameters: Username= “username”

Password= “Token”

OUTPUT:

Returns the Build Number and the URL of the job

STEP 4: Get the Build Status

Pass the Build URL from the previous API output to get the Build Status.

API: BuildUrl/api/json?

  Eg: https://jenkins.test.com/jenkins/job/test/job/access/63/api/json

Method: GET 

Parameters: Username= “username”

Password= “Token”

OUTPUT:

Returns the Build Status of the job.

 

API Build (game engine) Jenkins (software)

Opinions expressed by DZone contributors are their own.

Related

  • Building Micro-Frontends With Vue and Reusable Components
  • Build an AI Chatroom With ChatGPT and ZK by Asking It How!
  • Build Your Own AI Avatar App From Scratch in Less Than 8 Hours
  • 10 Best Practices to Launch APIs in 2023

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook