2

I've setup the Jenkins for the rails3 app to build the specs. One can find many posts via google on how to setup the build trigger on the github push.

But what I want is to build the new remote branch pushed to Github. e.g.

I've a repo origin/master. I cloned the repo, created a new branch, did some commits and pushed that branch to origin git push -u origin new_branch

Now I want the Jenkins to build this newly pushed branch on the origin.

If the build is successful, then Jenkins should merge it into origin/master automatically.

The Jenkins plugin has github, git plugin. But it requires to put the branch name. Instead I want to build the new_branch dynamically.

How can I setup such process?

millisami
  • 9,931
  • 15
  • 70
  • 112
  • This question already has an answer here: https://stackoverflow.com/a/39884629/4124574 – Mig82 May 13 '19 at 16:55
  • Possible duplicate of [Build only the Git branch that has been pushed to](https://stackoverflow.com/questions/27403576/build-only-the-git-branch-that-has-been-pushed-to) – Mig82 May 13 '19 at 16:55

2 Answers2

0

If I remember correctly branch name is not a required entry. You need to test it, but I think if you do not fill it, Jenkins tests all new commit in the repo regardless which branch is affected.

But I recommend you do not merge automatically. You do not want that, trust me. :-)

Gabor Garami
  • 1,245
  • 8
  • 26
  • So if it's already passed the tests from the build, what's wrong with merging to master? – Jordan May 18 '12 at 03:01
  • The problem is post-build actions runs always even if tests failed. And Jenkins currently do not have a merge-back option for git so you need to run it from shell script at post-build action. – Gabor Garami Jul 17 '12 at 16:11
  • Not sure which version of the Post-Build you're using, but mine has an option to trigger when the build is stable. I use the "Trigger Parameterized Build" plugin, which has a superset of the functionality as the regular Trigger Build plugin. – Jordan Jul 17 '12 at 20:23
  • So, if you're executing your shell scripts with -e, then it will exit immediately upon test failures, and will set your entire build to failed. – Jordan Jul 17 '12 at 20:24
  • @Jordan yes if you run shell scripts. But it is not always true – Gabor Garami Aug 14 '12 at 10:19
0

It seems can not do that with only github and gitgub parameter plugin. If you specify branch_regex*** in Branch to build, Jenkins always build the latest commit in the bunch of branches that it saw. Must specify a branch in order Jenkins to build on the latest commit in that branch. I also see some answer with Multi Branch Pipeline but not sure how to deploy that way. There is no specific instruction at all.