This post has NOT been accepted by the mailing list yet.
I couldn't find a solution the actually worked on the web but managed to 
work it out my self so though I would share the information. 

To add a job from Python 3.x to jenkins 1.547+ do the following: 

1. Using pip or otherwise install the "requests" module for python 3 

2. To post a job to jenkins you need a config.xml file for the job. If you 
need example content manually create a test job in jenkins and then on the 
jenkins server's local disk go to <jenkins home>\jobs\<job name>\config.xml 
copy and use this as a template. 

3. Once you have the xml file you need to POST it to http://<jenkinsserver 
and port>/createItem?name=<jobname> now to do this use the following code. 









*    def CreateJob(self, job_name, job_config_xml, url, username, 
password):         assert isinstance(job_name, str)         assert 
isinstance(job_config_xml, str)         assert isinstance(url, str)         
assert isinstance(username, str)         assert isinstance(password, str)   
      a = requests.post("%s/createItem" % url, params={"name":job_name}, 
data=job_config_xml, headers={"content-type":"text/xml"}, auth=(username, 
password))         return a.status_code==200*

job_config.xml should contain the config.xml file content as a string. 

BTW Don't try to pass the filename to requests.post instead of the file 
content as this seems to cause internal server error 500 and I'm not 
entirely sure why. It looks like the process causes file content to become 
corrupted when posted??? 

Also note that if you remove the headers={"content-type":"text/xml"} you 
will get Bad Request 400 because "text/html" is used by default which of 
course in our case is not correct because we are sending an XML file. 

Hope this helps. 

Del

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to