Title: Declarative Jenkins Pipeline to Poll different branches?
Tags: jenkins;continuous-integration;jenkinsfile
Question: We have a gitlab enterpise that host multiple project in one repo. Something like:
projectA/
projectB/
projectC/
We have three pipelines that will run base on changes(whitelist region) when polling. They will start polling when received a curl via the notifyCommit? in another job.
However, the pipeline can only work on branch that is run previously.
I have also try to use parameters $branch on branch to build and update the curl job with parameters like:
http://ourjenkins/git/notifyCommit?url=git_url.git&amp;branch=$GIT_BRANCH
but, it still will only poll the last run branch.
Does anyone know how we can have the declarative pipeline to poll multiple branches and run only base on whitelist directory changes?
Comment: Have you tried using a multibranch pipeline job? See https://jenkins.io/doc/book/pipeline/multibranch/

Comment: Yes, I definitely recommend the multibranch pipeline plugin. You can also filter by branch name if there is a common naming convention.


Here is another answer: One could use the PollSCM plugin.
https://jenkins.io/doc/book/pipeline/syntax/
triggers { pollSCM('H 4/* 0 0 1-5') }
The pollSCM trigger is only available in Jenkins 2.22 or later.

{'source': 'StackExchangeDataset', 'subset': 'devops.stackexchange.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:08/23/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<jenkins><continuous-integration><jenkinsfile>', 'Title': 'Declarative Jenkins Pipeline to Poll different branches?', 'ViewCount': 10060, 'id': 1832, 'user_AboutMe': '<p>Playing, working and learning to become a better craftsman. Started iOS development since iOS 3 with Objective-C. Moving on to Swift and continue plying the trade. Python, Django is usually my prefer framework in building the web aspect of stuff.</p>\n', 'user_AccountId': 8742556.0, 'user_DisplayName': 'Zac Kwan', 'user_Reputation': 151.0, 'user_Views': 3.0, 'user_id': 2834.0}}