Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic merge branch into master on successful build in travis

I've trying to do a setup, where I use Travis CI (http://www.travis-ci.org) to build and test my program each time I commit to GitHub. My GitHub setup is to have a master and a slave/test branch, which I commit to before merging into master. However, as of right now I'm doing the merging manually on GitHub.com, which I could like to automate, such that when a build is successful on Travis, I want to merge my slave/test branch into the master right away. Does anybody know how this is possible on Travis CI or another way of achieving this with Travis?

like image 899
Niels Sønderbæk Avatar asked Feb 28 '15 23:02

Niels Sønderbæk


People also ask

How do I force merge a branch into master?

First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch.

How do I merge branch into master or code?

Merging Branches At the top right of the Source Control panel, there is a button with an ellipses (…). If you want to merge two branches together, you can just click this button, go to the 'Pull, Push' option, then select 'Pull from…' and select a branch to merge with.

Can you merge a branch into master multiple times?

Actually yes you totally can, when you merge again it will bring over any commits that don't exist on production.


1 Answers

You can prepare script which will use for merge your branches. Travis set some useful environment variables which you can use in your script.

Merge script can look like:

if [ "$TRAVIS_BRANCH" != "test" ]; then 
    exit 0;
fi

export GIT_COMMITTER_EMAIL=...
export GIT_COMMITTER_NAME=...

git checkout master || exit
git merge "$TRAVIS_COMMIT" || exit
git push ... # here need some authorization and url

Next you can put in .travis.yml

after_success: ./merge_script.sh

More info:

  • http://docs.travis-ci.com/user/ci-environment/#Environment-variables
  • http://docs.travis-ci.com/user/build-lifecycle/
like image 117
Slawomir Jaranowski Avatar answered Sep 30 '22 11:09

Slawomir Jaranowski