Notebook to test api4jenkins - create job, update job, create folder, create credentials
To run:
- Clone the repository
cd evalApi4Jenkins/
- Create and activate virtualenv
pip install -r requirements.txt
- Open Jupyter notebook server
jupyter notebook
- Open and run
test.ipynb
Notes:
-
For creating custom jobs through code, we first created a manual job, fetch a job using
manualJob = j.get_job('Python-Application')
and fetch its xml usingxml = manualJob.configure()
. Then we fortmatted the xml, changing the description and git url. Then finally we created a similar Pipeline job through code using createPipeline() function, passing a new name and the formatted xml string. -
500: Internal server error was faced in creating a PipelineJob using the createPipeline() function, due to exact formatting of the XML string. There should be no preceding spaces in an XML string.
-
How I figured out the issue mentioned above ? I checked Jenkins system logs from
http://localhost:8080/log/all
Or Manage Jenkins --> System Logs --> All logs in WebApp. Finally solved it following the issue, referenced from StackOverFlow -
To further create different types of jobs in Jenkins, we will first create manual Jobs, fetch their XML, identify differences in XML and create small snippets for different jobs like Pipleline, Mulitbranch pipeline, folder, etc. Furthermore depending upon the job we are creating we will need to parse and create the custom XML using these snippets and finally create the job. We may need to define custom createJobs() functions for different jobs we are creating.