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?
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.xmlthat 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
- 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:
mylocalconfig.xml(from step 1) as a template,
mylocalconfig.xmlwith the right git repo path to use in Step 2 and create a job using the Remote access API.