Create jobs and execute them in jenkins using REST

前端 未结 5 1076
借酒劲吻你
借酒劲吻你 2021-01-30 23:17

I am trying to create a WCF REST client that will communicate to Jenkins and create a job from an XML file and then build the job. My understanding is that you can do that with

5条回答
  •  广开言路
    2021-01-31 00:04

    Usually, when parsing through the documentation, it can take one or two days. It is helpful to be able to access code or curl commands to get you up and running in one hour. That is my objective with a lot of third party software.

    See the post at http://scottizu.wordpress.com/2014/04/30/getting-started-with-the-jenkins-api/ which lists several of the curl commands. You will have to replace my.jenkins.com (ie JENKINS_HOST) with the your own url.

    To create a job, for instance, try:

    curl -X POST -H "Content-Type:application/xml" -d "" "http://JENKINS_HOST/createItem?name=AA_TEST_JOB2"
    

    This uses a generic config. You can also download a config from a manually created job and then use that as a template.

    curl "http://JENKINS_HOST/job/MY_JOB_NAME/config.xml" > config.xml
    curl -X POST -H "Content-Type:application/xml" -d @config.xml "http://JENKINS_HOST/createItem?name=AA_TEST_JOB3" 
    

    To execute the job (and set string parameters), use:

    curl "http://JENKINS_HOST/job/MY_JOB_NAME/build"
    curl "http://JENKINS_HOST/job/MY_JOB_NAME/buildWithParameters?PARAMETER0=VALUE0&PARAMETER1=VALUE1"
    

提交回复
热议问题