| 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. |