| ||||
REST APIMany 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.
For more information about remote API in Jenkins, see the documentation. Controlling the amount of data you fetchThe 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:
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. Fetch/Update config.xmlTo programmatically obtain config.xml, hit this URL. You can also POST an updated config.xml to the same URL to programmatically update the configuration of a job. Delete a jobTo programmatically delete this job, do HTTP POST to this URL. Fetch/Update job descriptionthis URL can be used to get and set just the job description. POST form data with a "description" parameter to set the description. Perform a buildTo programmatically schedule a new build, post to this URL. If the build has parameters, post to this URL and provide the parameters as form data. Either way, the successful queueing will result in 201 status code with Location HTTP header pointing the URL of the item in the queue. By polling the api/xml sub-URL of the queue item, you can track the status of the queued task. Generally, the task will go through some state transitions, then eventually it becomes either cancelled (look for the "cancelled" boolean property), or gets executed (look for the "executable" property that typically points to the AbstractBuild object.) To programmatically schedule SCM polling, post to this URL. If security is enabled, the recommended method is to provide the username/password of an account with build permission in the request. Tools such as curl and wget have parameters to specify these credentials. Another alternative (but deprecated) is to configure the 'Trigger builds remotely' section in the job configuration. Then building or polling can be triggered by including a parameter called token in the request. Disable/Enable a jobTo programmatically disable a job, post to this URL. Similarly post to this URL for enabling this job. |
Page generated: 25-Dec-2024 08:25:25Jenkins ver. 1.570 |