Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-58787

Be able to create a job posting config.xml - Or improve docs

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I want to be able to create jobs just by posting config.xml to the jenkins instance using the httprequest step

       

       

      def response = httpRequest authentication: 'JENKINS', customHeaders: [[maskValue: false, name: 'Content-type', value: 'application/xml']], 
      ignoreSslErrors: true, outputFile: 'config.xml', responseHandle: "STRING", url: 'http://localhost:8080/job/FOLDER/job/template/config.xml', 
      validResponseCodes: '100:399' 
      def myxml= "'"+response.content+"'"
      def response1 = httpRequest authentication: 'JENKINS', customHeaders: [[maskValue: false, name: 'Content-Type', value: 'TEXT_PLAIN'],
      [maskValue: false, name: 'requestBody', value: myxml],
      [maskValue: false, name: 'consoleLogResponseBody', value: 'true'],
      [maskValue: false, name: 'authentication', value: 'BASIC']
      ], httpMode: 'POST', ignoreSslErrors: true, url: "http://localhost:8080/createItem?name=new_job" 
      

      Or

      def response = httpRequest authentication: 'JENKINS', customHeaders: [[maskValue: false, name: 'Content-type', value: 'application/xml']], 
      ignoreSslErrors: true, outputFile: 'config.xml', responseHandle: "STRING", url: 'http://localhost:8080/job/FOLDER/job/template/config.xml', 
      validResponseCodes: '100:399' 
      def myxml= "'"+response.content+"'"
      def response1 = httpRequest authentication: 'JENKINS', customHeaders: [[maskValue: false, name: 'Content-Type', value: 'multipart/form-data'],
      ], httpMode: 'POST',multipartName: 'config.xml', ignoreSslErrors: true, url: "http://localhost:8080/createItem?name=new_job"   
      

       

      But this renders a 400 error

      hudson.AbortException: Fail: the returned code 400 is not in the accepted range: [[100‥399]]
      	at jenkins.plugins.http_request.HttpRequestExecution.responseCodeIsValid(HttpRequestExecution.java:353)
      	at jenkins.plugins.http_request.HttpRequestExecution.processResponse(HttpRequestExecution.java:363)
      	at jenkins.plugins.http_request.HttpRequestExecution.authAndRequest(HttpRequestExecution.java:279)
      	at jenkins.plugins.http_request.HttpRequestExecution.call(HttpRequestExecution.java:215)
      Caused: java.lang.IllegalStateException
      	at jenkins.plugins.http_request.HttpRequestExecution.call(HttpRequestExecution.java:218)
      

       

      It would be good to have an improvement allowing this to work or improve the documentation on this regard.

        Attachments

          Activity

          mcardenasblanco Manuel Cardenas created issue -
          janario Janario Oliveira made changes -
          Field Original Value New Value
          Resolution Not A Defect [ 7 ]
          Status Open [ 1 ] Closed [ 6 ]

            People

            Assignee:
            janario Janario Oliveira
            Reporter:
            mcardenasblanco Manuel Cardenas
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: