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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Build Your First Knowledge Graph From Unstructured Documents Using Python
  • 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

Trending

  • Three Measured Outcomes of Manually Scaling Fleet in Prod
  • Every Acquisition Promises One Company. Most Deliver Two.
  • Why Your GPU Fleet Is Both Full and Idle: Building a Capacity Orchestration Layer
  • You Don't Have to Pick One: A Hybrid Approach to Enterprise Data Refresh

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Apr. 10, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
29.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Build Your First Knowledge Graph From Unstructured Documents Using Python
  • 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

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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