Issue
I am using Python 2.7 and Jenkins.
I am writing some code in Python that will perform a checkin and wait/poll for Jenkins job to be complete. I would like some thoughts on around how I achieve it.
- Python function to create a check-in in Perforce-> This can be easily done as P4 has CLI
- Python code to detect when a build got triggered -> I have the changelist and the job number. How do I poll the Jenkins API for the build log to check if it has the appropriate changelists? The output of this step is a build url which is carrying out the job
- How do I wait till the Jenkins job is complete?
Can I use snippets from the Jenkins Rest API or from Python Jenkins module?
Solution
You can query the last build timestamp to determine if the build finished. Compare it to what it was just before you triggered the build, and see when it changes. To get the timestamp, add /lastBuild/buildTimestamp
to your job URL
As a matter of fact, in your Jenkins, add /lastBuild/api/
to any Job, and you will see a lot of API information. It even has Python API, but I not familiar with that so can't help you further
However, if you were using XML, you can add lastBuild/api/xml?depth=0
and inside the XML, you can see the <changeSet>
object with list of revisions/commit messages that triggered the build
Answered By - Slav
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)