Python script development

50 views
Skip to first unread message

Mohan Radhakrishnan

unread,
Oct 6, 2016, 8:23:59 AM10/6/16
to Jenkins Users
Hi,
       I am looking for some advice related to development of Python scripts that interact with Jenkins API's. How do you test the Jenkins integration in the IDE ? My goal is to check the build status and act on it. Can Jenkins run a mock build in the IDE to test my Python code ?

How is this done ?


Thanks,
Mohan

jer...@bodycad.com

unread,
Oct 6, 2016, 1:14:39 PM10/6/16
to Jenkins Users
Hi,

Just do normal unittest module implementation:

and add the xml xunit test module:
https://github.com/xmlrunner/unittest-xml-reporting/tree/master/

Then into Jenkins just run the unit test from the console invoke (bat "" or sh ""). Ex (this depends on you script implementation):
sh "python mytestScript.py -o outputdir/test.xml"

Parse the xunit result with the JUnitResultArchiver:
step([$class: 'JUnitResultArchiver', testResults: 'outputdir/*.xml']);

Jerome

jer...@bodycad.com

unread,
Oct 6, 2016, 1:17:07 PM10/6/16
to Jenkins Users
Sorry my bad, I missread the question, this doesn'T interact with Jenkins IDE API at all, sorry, reverse question, ignore my post, sorry.

You proabbly will have to create a dummy Jenkins server that reside into a VM or something like that and check if the command were operated. But I don't have a clear solution for this. Sorry again.

Jerome

Mohan Radhakrishnan

unread,
Oct 11, 2016, 7:02:52 AM10/11/16
to Jenkins Users
Are there some instructions to load Python code from disk as part of the build step ? This code should access Jenkins API. Is that possible ? I want to get the build status and act on it.

Mohan

Jérôme Godbout

unread,
Oct 11, 2016, 10:28:33 AM10/11/16
to jenkins...@googlegroups.com
Hi,
There's a JenkinsApi package for Python:

https://jenkinsapi.readthedocs.io/en/latest/

Not sure what is accessible during a pipeline or if this is just for completed build or old standard build for the Python API module (I haven't test this yet).

You probably could pass the current build result, current build number and the job name to your Python script so can reach the proper build info:

// Into Jenkins Pipeline
${env.JOB_BASE_NAME}
${env.BUILD_NUMBER}
${currentBuild.result}  // take care not set until something went wrong

As for launching Python script from buidl step see above, just use console command and start the process, if you need some complexe return value, a file could be used. Make sure the command return 0 if you want to continue and doesn't return bad code, else you will need a try/catch into your pipeline script.

Hope this help and I understood you properly this time, if not let us know,
Jerome

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/iGmqEq02ybI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/780238df-eafa-4388-8949-4ec1649a4c59%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages