-
Improvement
-
Resolution: Fixed
-
Minor
-
None
-
Powered by SuggestiMate
For the Github plugin, there is a "Build when a change is pushed to GitHub" option (https://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin) as well as for CVS a "post commit trigger" howto. (https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-UsingapostcommittriggerinCVS)
An option for the perforce plugin would be nice.
A build trigger... Something like "Build when a change is pushed to depot"
[JENKINS-25249] Post-commit hook for P4 plugin
[1] I guess you need a single entry point where the change-number is passed in. Then the P4 plugin could then work out which Jenkins job or jobs to trigger?
or ...
[2] A subscribe model, A bit like the old p4 review/reviews command, but for Jenkins jobs to subscribe to Perforce depot paths.
Design 1 is similar to what the Subversion plugin does. To use this with Subversion, the Subversion server is configured with a post-commit hook that makes a request to Jenkins over HTTP. One significant difference from your design is that the request also includes the changed paths as POST data, removing the need for Jenkins to ask the Subversion server for changes. See the Subversion plugin's wiki page for more details.
I like the POST data idea for change-list details. I may combine [1] and [2], using a web service for Jenkins to subscribe to and then use Perforce triggers to poke the web service.
[Perforce] [Web Service] [Jenkins] | | | | | <-----(subscribe)------ | | | | | ----(change-commit)---> [ ] | | [ ] ----(POST change)---> [ ]
Would this be a standalone web service, needing to be hosted outside Jenkins and Perforce? I'm no expert in the inner workings of Perforce so this might be the best solution, but requiring a third piece of software to be hosted is a drawback to me.
Realistically it is going to be a couple of months. In the mean-time, don't forget Perforce Swarm can do most of this already.
There is a Web Service project in progress, if I can add in a subscribe model, then the Jenkins side is relatively simple. With a granular subscribe model each Jenkins Job can subscribe to a set of paths, then the Web Service invokes the build. This approach is similar to the Swarm model, but with the benefit of automatic Jenkins Job registration.
I have been experimenting with a trigger based endpoint in Jenkins. I have seen a few plugins take this approach (https://github.com/jenkinsci/bitbucket-plugin).
I have submitted a change, if you are interested in trying it out let me know and I can send you the details.
Code changed in jenkins
User: Paul Allen
Path:
src/main/java/org/jenkinsci/plugins/p4/trigger/P4Hook.java
src/main/java/org/jenkinsci/plugins/p4/trigger/P4Trigger.java
src/main/java/org/jenkinsci/plugins/p4/workflow/P4PublishStep.java
src/main/java/org/jenkinsci/plugins/p4/workflow/P4TaggingStep.java
src/main/resources/org/jenkinsci/plugins/p4/trigger/P4Trigger/P4TriggerAction/index.jelly
src/main/webapp/script.js
src/main/webapp/style.css
http://jenkins-ci.org/commit/p4-plugin/7bc19f9ca1b79a630af99c2332c8769954687e21
Log:
Perforce triggered polling BETA.
Perforce triggers on a change-submit and sends a POST to the endpoint
http://${JENKINS}/p4/change with the data:
Note: ‘change’ is not used (yet), but ‘p4port’ MUST match the
credential in the Jenkins Job.
Paul, the log section of your change discusses Perforce triggering on a change-submit. It should have Perforce triggering on a change-commit.
The difference between the two that is important here is the change number passed to the change-submit is the change number of the pending change being submitted. The change number passed to the change-commit is the number of the change after it has been committed. Most of the time these two are not the same and if they are different they pending change list will no longer exist.
Hi Brian, thanks a very good point. Although I don't as yet use the change number, you are correct I should have referred to change-submit.
I have recently completed the post-commit feature. See change (19294)https://swarm.workshop.perforce.com/changes/19294
You will need to use the SNAPSHOT build to try this out before the 1.3.9 release!
Create a Perforce 'change-commit' trigger to POST a JSON payload to '/p4/change'
For example:
curl --header 'Content-Type: application/json' --request POST --data 'payload={change:200,p4port:perforce.com:1666}' http://jenkins:8080/p4/change
Only jobs registered will trigger, set 'Perforce triggered build.' under 'Build Triggers' in the configuration. The p4port in the JSON payload must match the Perforce Credentials P4Port.
You can test this by clicking on the 'P4 Trigger' button at the root Jenkins page.
Thank you very much Paul! will give a try and update here about outcome
Added some notes to the setup guide for the 1.3.9 release:
https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md#triggering
Thanks Paul! I tried this on freestyle type job and found it working. The workflow type jobs have been moved to pipeline-jobs does this trigger mechanism will work to initiate the pipeline jobs also? is there any future plan to introduce the Jenkinsfile kind of support like github?
Great to hear it is working for you.
Support for pipeline and multi-branch (https://jenkins.io/doc/pipeline/) are on my list, but I don't have a lot of free time at the moment. If you get there first, I would be happy to review a pull request.
I did some work on this to make it work with Pipeline: https://github.com/Dohbedoh/p4-plugin/commit/8602fddd4e1ebb45e45e8ed886b4fa9eccc2deed
I am gonna enrich this with tests and submit a PR as soon as possible.
Hi Paul, Alan, does the build filter 'polling per change' works with this new p4 hook?
Is variable P4_CHANGELIST exposed to pipeline jobs? I tried ${env.P4_CHANGELIST} in jenkinsfile but its not working.
The 'polling per change' should work with the new P4 Trigger feature; if you find an issue please open a New JIRA Issue.
The Workflow --> Pipeline changes are under way and are intended to support the environment.
p4paul: It would be nice if there was a way to get the changelist that was sync'd by the p4sync operation. It could populate the P4_CHANGELIST variable like it used to, but users would have to be aware that the variable only represents the most recent sync operation. Another possibility would be for p4sync to just return the changelist it used for the sync.
Code changed in jenkins
User: Allan Burdajewicz
Path:
src/main/java/org/jenkinsci/plugins/p4/trigger/P4Trigger.java
src/test/java/org/jenkinsci/plugins/p4/client/ConnectionTest.java
http://jenkins-ci.org/commit/p4-plugin/2c179882189200b39d92fddf6f335e1694c2781d
Log:
JENKINS-25249: Fixed trigger probe method for pipeline compatibility.
Code changed in jenkins
User: Allan Burdajewicz
Path:
src/test/java/org/jenkinsci/plugins/p4/client/ConnectionTest.java
http://jenkins-ci.org/commit/p4-plugin/459dcebc4f83bc2b114b2f6e8bcb18382eea02f2
Log:
JENKINS-25249: Added tests for P4 Trigger and Workflow
Compare: https://github.com/jenkinsci/p4-plugin/compare/2c1798821892^...459dcebc4f83
Code changed in jenkins
User: Paul Allen
Path:
src/main/java/org/jenkinsci/plugins/p4/trigger/P4Trigger.java
src/test/java/org/jenkinsci/plugins/p4/client/ConnectionTest.java
http://jenkins-ci.org/commit/p4-plugin/e9a370b5ec856951e944086392962592696e67ee
Log:
Merge pull request #24 from Dohbedoh/JENKINS-25249
Jenkins 25249
Compare: https://github.com/jenkinsci/p4-plugin/compare/8a358595926e...e9a370b5ec85
Code changed in jenkins
User: Allan Burdajewicz
Path:
src/main/java/org/jenkinsci/plugins/p4/trigger/P4Hook.java
src/main/java/org/jenkinsci/plugins/p4/trigger/P4Trigger.java
http://jenkins-ci.org/commit/p4-plugin/d6a42f514e3e7c2b66a2eda04e4f706702c9faeb
Log:
JENKINS-25249: Fixed Null Pointer dereference
Code changed in jenkins
User: Paul Allen
Path:
src/main/java/org/jenkinsci/plugins/p4/trigger/P4Hook.java
src/main/java/org/jenkinsci/plugins/p4/trigger/P4Trigger.java
http://jenkins-ci.org/commit/p4-plugin/c9f91403eb60f93ea5d9da3dc22716e84c6bad23
Log:
Merge pull request #26 from Dohbedoh/hotfix/JENKINS-25249
JENKINS-25249: Fixed Null Pointer dereference
Compare: https://github.com/jenkinsci/p4-plugin/compare/df32b4ec5814...c9f91403eb60
Would be great to trigger builds from perforce instead of having to poll. Current url trigger mechanism in Jenkins is not realistic because you would need to create new perforce trigger for every job.