Ashley
Ashley

Reputation: 1629

Jenkins scripted pipeline to trigger job only when commits happen in Github

We use CloudBees-2.138.2.2 Jenkins and have had lot of challenges to trigger jenkins jobs only based on commits in our Github repo. I am still looking for the exact working script for scripted pipeline and not declarative one.

so For example :- pipelineTriggers([cron('0-59/2 * * * *')]), works but pipelineTriggers([pollSCM('0-59/2 * * * *')]), never works despite new commits

Upvotes: 1

Views: 1465

Answers (2)

Nicodemuz
Nicodemuz

Reputation: 4144

You can try adding the following in your scripted pipeline

properties([pipelineTriggers([githubPush()])])

Upvotes: 1

Ashley
Ashley

Reputation: 1629

was able to make it work using :-

pipelineTriggers([pollSCM('* * * * *')]) under properties

This way the job polls the repo every minute and will trigger build only when it detects a new commit.

Upvotes: 1

Related Questions