Remote API [Jenkins] (2024)

Many objects of Jenkins provide the remote access API. They are available at /jenkins/.../api/ where "..." portion is the object for which you'd like to access.

XML API
Access data exposed in HTML as XML for machine consumption. Schema is also available.

You can also specify optional XPath to control the fragment you'd like to obtain (but see below). For example, ../api/xml?xpath=/*/*[0].

For XPath that matches multiple nodes, you need to also specify the "wrapper" query parameter to specify the name of the root XML element to be create so that the resulting XML becomes well-formed.

Similarly exclude query parameter can be used to exclude nodes that match the given XPath from the result. This is useful for trimming down the amount of data you fetch (but again see below). This query parameter can be specified multiple times.

XPath filtering is powerful, and you can have it only return a very small data, but note that the server still has to build a full DOM of the raw data, which could cause a large memory spike. To avoid overloading the server, consider using the tree parameter, or use the xpath parameter in conjunction with the tree parameter. When used together, the result of the tree parameter filtering is built into DOM, then the XPath is applied to compute the final return value. In this way, you can often substantially reduce the size of DOM built in memory.

JSON API
Access the same data as JSON for JavaScript-based access. tree may be used.
Python API

Access the same data as Python for Python clients. This can be parsed into Python objects as ast.literal_eval(urllib.urlopen("...").read()) and the resulting object tree is identical to that of JSON.

For more information about remote API in Jenkins, see the documentation.

Controlling the amount of data you fetch

The tree query parameter allows you to explicitly specify and retrieve only the information you are looking for, by using an XPath-ish path expression. The value should be a list of property names to include, with sub-properties inside square braces. Try tree=jobs[name],views[name,jobs[name]] to see just a list of jobs (only giving the name) and views (giving the name and jobs they contain). Note: for array-type properties (such as jobs in this example), the name must be given in the original plural, not in the singular as the element would appear in XML (<job>). This will be more natural for e.g. json?tree=jobs[name] anyway: the JSON writer does not do plural-to-singular mangling because arrays are represented explicitly.

For array-type properties, a range specifier is supported. For example, tree=jobs[name]{0,10} would retrieve the name of the first 10 jobs. The range specifier has the following variants:

  • {M,N}: From the M-th element (inclusive) to the N-th element (exclusive).
  • {M,}: From the M-th element (inclusive) to the end.
  • {,N}: From the first element (inclusive) to the N-th element (exclusive). The same as {0,N}.
  • {N}: Just retrieve the N-th element. The same as {N,N+1}.

Another way to retrieve more data is to use the depth=N query parameter. This retrieves all the data up to the specified depth. Compare depth=0 and depth=1 and see what the difference is for yourself. Also note that data created by a smaller depth value is always a subset of the data created by a bigger depth value.

Because of the size of the data, the depth parameter should really be only used to explore what data Jenkins can return. Once you identify the data you want to retrieve, you can then come up with the tree parameter to exactly specify the data you need.

Other Useful URLs

Build number
This URL returns the build number in text/plain format.
Build timestamp
This URL returns the build timestamp. You can also use the format query parameter to control the date format, which follows the SimpleDateFormat format pattern. (example) You can also use the Accept-Language HTTP header to control the locale in which the date is formatted.

Accessing Progressive Console Output

You can retrieve in-progress console output by making repeated GET requests with a parameter. You'll basically send GET request to this URL (or this URL if you want HTML that can be put into <pre> tag.) The start parameter controls the byte offset of where you start.

The response will contain a chunk of the console output, as well as the X-Text-Size header that represents the bytes offset (of the raw log file). This is the number you want to use as the start parameter for the next call.

If the response also contains the X-More-Data: true header, the server is indicating that the build is in progress, and you need to repeat the request after some delay. The Jenkins UI waits 5 seconds before making the next call. When this header is not present, you know that you've retrieved all the data and the build is complete.

Remote API [Jenkins] (2024)

FAQs

What is the Jenkins remote access API? ›

Jenkins API Client is an object oriented ruby wrapper project that consumes Jenkins's JSON API and aims at providing access to all remote API Jenkins provides. It is available as a Rubygem and can be useful to interact with the Job, Node, View, BuildQueue, and System related functionalities.

What is remote API? ›

A Remote API is an API that is deployed separately from the BFF host. Remote APIs use access tokens to authenticate and authorize requests, but the frontend does not possess an access token to make requests to remote APIs directly.

How to integrate API in Jenkins? ›

To set up a Jenkins integration for your API, first create an API token in Jenkins and then configure your API in Postman. After you set up the integration, you can view the status of builds or start a new build, all from within Postman.

How to access Jenkins remotely? ›

Create a remote Jenkins build trigger in three steps
  1. Create a Jenkins build job and enable the Trigger builds remotely checkbox.
  2. Provide an authentication token; This can be any text string of your choice.
  3. Invoke the Jenkins build URL to remotely trigger the build job.
Dec 22, 2020

How to call a Jenkins job using API? ›

How to call Jenkins API
  1. Log in to Jenkins using your Jenkins credentials.
  2. Click on your username or the user icon in the top-right corner of the Jenkins interface to access your user profile.
  3. Locate the "Configure" or "Configure User" option and click on it.
Jun 8, 2023

How to deploy API using Jenkins? ›

  1. Step 1 - Setup Jenkins.
  2. Step 2 - Create GitHub repositories. Step 2.1 - Setup source repository. Step 2.2 - Setup deployment repository.
  3. Step 3 - Setup JFrog Artifactory.
  4. Step 4 - Setup API-M instances.
  5. Step 5 - Configure Jenkins Jobs. Step 5.1 - Setup Global variables. Step 5.2 - Setup Artifact build and upload job.

What is the API access? ›

API access refers to the ability to interact with and utilize the functionalities provided by an Application Programming Interface (API). It enables applications, systems, and developers to communicate with other software systems, accessing their data, services, or features.

What is Jenkins remoting? ›

Jenkins Remoting is a library, and executable Java archive, which implements the communication layer in Jenkins. This includes the TCP-based communication protocols, remote procedure calls, class loading, data streaming, etc.

What is the use of Jenkins API token? ›

You can have multiple active API tokens at the same time and track the usage of your tokens. You can also revoke API tokens as needed. You can also use the Jenkins API token for authentication when you're using the Jenkins CLI. In the Jenkins banner frame, click your user name to open the user menu.

How to connect Jenkins to remote server? ›

Jenkins deploying at remote server
  1. Locate the private key file that you want to use for SSH authentication. ...
  2. Copy the private key file to the agent node. ...
  3. Set the correct permissions on the private key file. ...
  4. Update your Jenkins pipeline to use the correct path to the private key file.
Mar 16, 2023

Top Articles
Latest Posts
Article information

Author: Tish Haag

Last Updated:

Views: 6079

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.