How to update job config files using the REST API and cURL?

Article ID:218353308
1 minute readKnowledge base

Issue

I would like to be able to update job config files remotely using the Jenkins REST API and cURL.

Environment

  • CloudBees Jenkins Enterprise

  • Remote Access API

  • cURL

Resolution

Here is an example that I used to test this locally:

# Get current config
curl --user $USER:$API_TOKEN -X GET https://localhost:8080/job/test/config.xml -o mylocalconfig.xml

# Post updated config
curl --user $USER:$API_TOKEN -X POST https://localhost:8080/job/test/config.xml -H 'Content-Type: application/xml' --data-binary "@mymodifiedlocalconfig.xml"

Where you will have to replace:

  • $USER:$API_TOKEN with your username and an API token

  • localhost:8080 with your Jenkins URL

  • test with your job name

See Remote Access API for more.

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.