How to trigger a build on commit to branch in declarative pipeline

0 votes
Jul 9, 2020 in Jenkins by Madhura
• 130 points
3,359 views

1 answer to this question.

+1 vote

Hi@Madhura,

You can use triggers keyword in your DSL code as shown below.

 triggers {
       // poll repo every 2 minute for changes
       pollSCM('*/2 * * * *')

It will check every two seconds if anything changes occur and build your Job automatically.

answered Jul 9, 2020 by MD
• 95,460 points
Looks more like "every two mins", and doesn't look like branch based...

How would you add a condition to say something like "if (env.BRANCH_NAME == 'staging') { go_with_stages } else { do_nothing }" ? would it be possible to do with the pipeline?

Hi@Alex,

Yes. But the Job will run if you commit anything in your branch. Otherwise, it will just monitor. But according to your requirement, the poll SCM will work. 

Related Questions In Jenkins

+1 vote
1 answer

How to extract a substring of a string in a declarative pipeline code?

This would have been more easier using ...READ MORE

answered Aug 16, 2019 in Jenkins by Sirajul
• 59,230 points
47,886 views
0 votes
1 answer
0 votes
2 answers

how to execute a shell script post build step in Jenkins?

You could use the Post Build Task Plugin ...READ MORE

answered Jul 31, 2019 in Jenkins by Sirajul
• 59,230 points
29,538 views
0 votes
1 answer

How to fix a broken build for my project in jenkins?

The user needs to open the console ...READ MORE

answered Oct 11, 2019 in Jenkins by Sirajul
• 59,230 points
8,746 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,059 views
+2 votes
1 answer
+5 votes
3 answers

How to trigger a Jenkins pipeline A in another Jenkins pipeline B?

You can run the following code, its ...READ MORE

answered Jul 5, 2018 in Jenkins by Sophie may
• 10,620 points
119,784 views
+1 vote
3 answers

How to auto build a job in jenkins if there is any change in code on Github repository?

To automatically run build on code commit, follow ...READ MORE

answered Jul 31, 2019 in Jenkins by Sirajul
• 59,230 points
78,885 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP