susanoo susanoo - 1 year ago 88
reST (reStructuredText) Question

Update Git repository of a jenkins jobs using rest

I am taking job name,git repository,git username and password as input from the user.I am able to create a jenkins job using rest but I am not able to set that job's git repository path.So how to connect a jenkins job with a git repository using rest?

Answer Source

Maybe you can use the workaround presented in "How to create a job using the REST API and cURL "


Create a job using the UI. This job can be used to create a base config that can be used to create new jobs.

To retrieve the job config.xml that you made via the UI, to use for creating new jobs:

curl -X GET http://developer:developer@localhost:8080/job/test/config.xml -o mylocalconfig.xml

Obviously, replace:

  • developer:developer with your username:password
  • localhost:8080 with your Jenkins URL
  • test with the name of the job that you created via the UI


use this config to create a new job:

curl -s -XPOST 'http://developer:developer@localhost:8080/createItem?name=yourJobName' --data-binary @mylocalconfig.xml -H "Content-Type:text/xml"

The idea is to:

  • use mylocalconfig.xml (from step 1) as a template,
  • change the content of mylocalconfig.xml with the right git repo path to use in Step 2 and create a job using the Remote access API.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download