1

I've installed this p4 plugin in a Jenkins job. This scynces a workspace to the latest change and then builds. Now, under "Build Triggers", I've chosen "Build periodically" and set the job to run every 10 mins. Is there a way do trigger this Jenkins job when a new submit comes in to P4? Do I use the plugin or do I do something with "p4 trigger"? If so, how can I do this?

Thank you!

dr.jekyllandme
  • 613
  • 2
  • 11
  • 22

2 Answers2

5

Under the same Build Triggers section, there is an option named Poll SCM. Enable that option. This option is present by default when you install Jenkins. It does exactly what you're looking for. It will trigger build as soon as it detects a new commit in P4. Although not necessary, it's good to enable Quiet period too. This option is under Advanced Project Options section (refer snapshot below). Also read Help (?) that's provided with every option to gain better understanding of what it does.

enter image description here

Technext
  • 7,887
  • 9
  • 48
  • 76
  • Isn't it better to leave the Quiet period disabled if you have the hardware to support it? Having one build per change means more information when something goes wrong, and more information is better. – David Pärsson Aug 10 '15 at 12:16
  • It's a matter of personal choice i would say. I would always prefer having Quiet period enabled as that would make the Poll SCM feature look less bad than what it would be with no Quiet period enabled. For ex., if i have three commits pushed to central repository within an interval of 5 secs each, i would prefer triggering a build with a Quiet period of say, 15 sec. Obviously, i will not know beforehand which (one, two or all three) of the three commits will be included in that 15 secs Quiet period. ;) Sometimes, i might get lucky. :) – Technext Aug 10 '15 at 15:48
  • OTOH, as you said, having more frequent builds by disabling Quiet period might actually help you narrow down the culprit easily. Defining Quiet period or Poll SCM interval itself would depend on various factors such as frequency of commits, time taken by each build etc. If each build takes a long time to complete, i would prefer having Quiet period enabled so that i could figure out the post-build issue quickly by analyzing the application logs (even if multiple commits went in a given build) instead of waiting for each subsequent build to finish. – Technext Aug 10 '15 at 15:56
  • IMO, using Poll SCM itself is a resource-intensive operation and an inefficient way to trigger build on check-ins. A far better approach would be to implement a hook (hopefully almost every major VCS might be having this feature) which checks for commits during a check-in and calls the corresponding Jenkins job using plugins such as [Build Token Root Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin) – Technext Aug 10 '15 at 15:58
  • Agreed, a hook would be much better, but that's [not yet supported](https://issues.jenkins-ci.org/browse/JENKINS-25249) by the P4 Plugin. – David Pärsson Aug 11 '15 at 07:03
  • Actually, i was referring to implementing hook on the P4 server. This will remove dependency on the plugin (JIRA cited by you). Once you have the server-side hook in place, all you have to do is call the Jenkins job remotely from the hook itself as soon as a commit is pushed to P4 server. This will obviously require your P4 administrator's help. – Technext Aug 11 '15 at 07:16
  • This would either require the P4 server to know which Jenkins jobs to trigger (which isn't acceptable in my case), or it would require some efforts to implement. – David Pärsson Aug 11 '15 at 08:14
1

This is how to set up p4 url triggers.

  1. Generate your API key, click your username in the top right > click configure > then generate a new API token! enter image description here

  2. In your build configuration check the "Trigger builds remotely (e.g., from scripts)", then write whatever you want as the authentication token I wrote "MadeUpToken" enter image description here

  3. The next step is to run this curl command:

curl -X POST -L --user your-jenkins-username:11170e251c58b2768d4d26bc1db3d6395f https://Your-Jenkins-URL.com/job/Local_UE4/build?token=MadeUpToken

enter image description here

Tonia Sanzo
  • 335
  • 2
  • 10