3
votes

I'm using the Jenkins Perforce plugin, and polling a workspace for changes, then a build is running on the caught changelist.

The problem: In case there are multiple changelists caught in the same poll, the build is running ONLY on the last changelist (and not on all of the changelists)

P4_CHANGELIST contains the last changelist.

How can I run the build on each of the caught changelists?

4
Just making sure I understand: you want to force a separate build for each individual changelist as opposed to letting Jenkins group multiple changelists into a single build, right? Presumably you're trying to confirm that each changelist does not cause a problem?gaige
Yes, exactly. I want to build each seperate changelist. But if there isn't a possible way to do that, I still would like to know the list of caught changelists. Is there a way to do that?Avi Rosenfeld
I believe the answer is "you can't", based on This Question, however there are some suggestions on how to limit the problem.gaige
Thanks for the link. It says there " As of now Jenkins does not have the feature to split build into single builds on multiple SVN commit.". But, is there a way to get the list of changelists of the a single poll?Avi Rosenfeld
I have the opposite problem, On latest jenkins, I cant get the build to pull all of the changes at once and build them. I 20 minutes a build with 5 commits an hour and it isn't working for me.Dan

4 Answers

2
votes

As for running a build for each changelist, that is a feature request that hasn't yet been acted upon (first answered in This Question).

The specific changelist information is in the metadata for the job. I'm not sure you can get to it during the build phase, but you can definitely see it afterwards. The Summary of Changes section shows just the changelists since the last build.

In the builds directory for each job, there is a changelog.xml file that contains entries for each individual "changelog entry", which in the case of Perforce is a changelist. The changenumber element of each entry indicates the changelist number from perforce.

Finally, if you want to scrape the information for an automated process external to the Jenkins server, you can retrieve XML data on the last build by retrieving:

http://{sereveraddress}/job/{jobname}/lastSuccessfulBuild/api/xml

Which will return an XML structure containing the changeSet list of items which each have the changeNumber in them (along with the msg and each affectedPath). This data is also available in json.

2
votes

The more correct way of implementing this would be to parameterize your job to run at a specific changeset, then write a post-commit trigger in your perforce server that starts the Jenkins job remotely, either using the CLI or through something as simple as curl. This has the added advantage of building every changeset as they are committed, rather than in batches whenever the polling interval occurs.

As has been mentioned, this functionality doesn't exist in Jenkins core yet. Fortunately, there is a ticket open for adding this functionality directly to the Perforce Plugin. This would essentially cause it to only build the next change whenever it is run, and should be fairly simple to implement, but will have the disadvantage of only running one build per polling period.

https://issues.jenkins-ci.org/browse/JENKINS-17889

0
votes

Solution was found!

The problem was with the polling that didn't provided the multiple changelists info. Instead of polling the branch with Jenkins\Perforce plugin, I used a Perforce query to find all queries that were submitted since last build.

Here is what I did in order to solve the problem:

  1. I've created a standalone job to build a changelist by it's a number.
  2. I've created a job the finds all changelists that were submitted since the last changelist build (param LATEST_CHANGELIST_NUMBER that is saved in a file or registry). In order to do that I used the Perforce query: p4 changes "//projects/BRANCH_NAME/...@>LATEST_CHANGELIST_NUMBER"

Then I build each of the found changelists and update the LATEST_CHANGELIST_NUMBER (in a file for example).

It works fine! Thanks for the ideas!

0
votes

Polling Per Change

Checked the builds will occur with 1 change per build, unchecked you gat all changes since the quiet period started.