3

I want to set the Github repository url in http://host-ip:8080/job/my_project/configure jenkins page via code each time I spawn a new Jenkins container.

I read that this can be done with python-jenkins's reconfig_job function by replacing the config.xml .

Well how would I do that?

Kostas Demiris
  • 3,415
  • 8
  • 47
  • 85

1 Answers1

3

You have some clues in "How can I update a jenkins job using the api?"

For instance, since you spawn a new Jenkins container, you can docker cp an updated config.xml to the container (at the right path for that job)

(the OP Kostas Demiris confirms in the comments it works, when run in git bash)

You can also use one of the Jenkins API libraries, but check if a simple curl is enough first

#Get the current configuration and save it locally
curl -X GET http://user:password@jenkins.server.org/job/myjobname/config.xml -o mylocalconfig.xml

#Update the configuration via posting a local configuration file
curl -X POST http://user:password@jenkins.server.org/job/myjobname/config.xml --data-binary "@mymodifiedlocalconfig.xml"

The updated Jenkins doc mentions (for updating just one parameter in an existing config job):

Simple example - sending "String Parameters":

curl -X POST JENKINS_URL/job/JOB_NAME/build \
  --data token=TOKEN \
  --data-urlencode json='{"parameter": [{"name":"id", "value":"123"}, {"name":"verbosity", "value":"high"}]}'

Another example - sending a "File Parameter":

curl -X POST JENKINS_URL/job/JOB_NAME/build \
  --user USER:PASSWORD \
  --form file0=@PATH_TO_FILE \
  --form json='{"parameter": [{"name":"FILE_LOCATION_AS_SET_IN_JENKINS", "file":"file0"}]}'
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • With this command : curl -X POST http://username:password@host.com:8686/job/MyJob/config.xml --data-binary "@new_config.xml" from the directory of new_config PowerShell throws 'Invoke-WebRequest : A parameter cannot be found that matches parameter name 'X' ' – Kostas Demiris Oct 19 '15 at 13:38
  • 1
    @KostasDemiris Great! I have included your comment in the answer for more visibility. – VonC Oct 19 '15 at 14:13