18

I have researched this issue a lot and cannot find an answer to that, so I have setup a simple project on Jenkins before and I get all the perks of the "Build Triggers" tab where I can select exactly what could trigger the project build (for example pull requests).

However, in the Blue Ocean project I can only see these options under the specific branch > View Configuration, and it doesn't allow me to save any of the options configured, it just shows the configs and there is no save button. I have attached the screenshots below:

This is the Project > Configuration, it allows me to save changes and everything but has no option for build triggers. Project Configs

This is under Project > Branch (master) > View Configurations, it shows the build triggers I want but no option to apply these changes into that specific branch. Branch Configs

So, I guess the question is, how can I add the build triggers to my blue ocean pipeline?

Blizzard
  • 1,117
  • 2
  • 11
  • 28
  • 1
    Why don't Jenkins team consider this as a bug? – Shihe Zhang Jun 27 '18 at 06:04
  • @ShiheZhang I really don't understand either. I am not sure if it is brought up to them, but the answer below is only a partial answer. I should be able to handle this and a lot more through the "View Configurations" page. – Blizzard Jun 28 '18 at 16:22

1 Answers1

14

The build triggered seen under a branch should be the reflection of the trigger directive made in a Jenkinsfile directive which is either:

  • cron
    Accepts a cron-style string to define a regular interval at which the pipeline should be re-triggered, for example:

      triggers { cron('H */4 * * 1-5') }
    
  • pollSCM
    Accepts a cron-style string to define a regular interval at which Jenkins should check for new source changes. If new changes exist, the pipeline will be re-triggered. For example:

      triggers { pollSCM('H */4 * * 1-5') }
    
  • upstream
    Accepts a comma separated string of jobs and a threshold.
    When any job in the string finishes with the minimum threshold, the pipeline will be re-triggered. For example:

      triggers { upstream(upstreamProjects: 'job1,job2', 
                         threshold: hudson.model.Result.SUCCESS) }
    

That would be paired with a when directive, which specifies the branch

branch
Execute the stage when the branch being built matches the branch pattern given, for example:

when { branch 'master' }

Note that this only works on a multibranch Pipeline.


Nmaresh Kulkarni adds in the comments:

Looks like the remote trigger from script is not an option, and this option is must for folks behind a firewall.
The only way that I can think of is to create a fake trigger job, and configure that as an upstream trigger for my actual repo with Jenkinsfile.

 curl -X POST -u "$username:$api-token" "$jenkins-url/job/$job-name/job/$branch-name/build"

This API is handy to trigger remote builds within local network after pushing to GitHub or Azure repos.

(From "How to trigger Jenkins builds remotely and to pass parameters")

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you so much, been looking for an answer since forever! – Blizzard Dec 21 '17 at 04:17
  • Looks like the remote trigger from script is not an option, and this option is must for folks behind a firewall. The only way that I can think of is to create a fake trigger job, and configure that as an upstream trigger for my actual repo with Jenkinsfile. Any other options? – Amaresh Kulkarni Oct 18 '22 at 23:19
  • @AmareshKulkarni good point, I don't have another option at the moment. – VonC Oct 18 '22 at 23:26
  • @VonC looks like the notifyCommit is an option, but haven't been able to get it to work yet. I will post here, if that works out. – Amaresh Kulkarni Oct 19 '22 at 00:14
  • This is what I did to get this working.. curl -X POST -u "$username:$api-token" "$jenkins-url/job/$job-name/job/$branch-name/build" - This solution was quoted in another SO post or some other place, but I had to try some new options to get it it work – Amaresh Kulkarni Oct 19 '22 at 01:30
  • The solution that was quoted elsewhere had the buildWithParameters API and the job that I was trying to trigger was not built with any parameters, resulting in the failures. But otherwise, this API is handy to trigger remote builds within local network after pushing to GitHub or Azure repos. – Amaresh Kulkarni Oct 19 '22 at 01:52
  • @AmareshKulkarni Thank you for your feedback. I have included your comment in the answer for more visibility. Do you have the link to the other SO post you mention? – VonC Oct 19 '22 at 08:37
  • https://stackoverflow.com/questions/20359810/how-to-trigger-jenkins-builds-remotely-and-to-pass-parameters – Amaresh Kulkarni Oct 19 '22 at 09:26
  • @AmareshKulkarni Perfect, thank you. I have included that reference in the answer. – VonC Oct 19 '22 at 09:39