#ci/cd
Or how to let Travis-CI merge into master if the build is successful.
It is way easier than I thought.
travis
gem.travis.yml
is set up).This is required because we don't want to write our Github username and password anywhere. Go to your Github Application Settings and create a new Token.
Even the Token is not something to post on your Twitter.
travis encrypt -a - GITHUB_TOKEN=your_generated_token
Your token will be encrypted and automatically added to your .travis.yml
file.
'nuff said. Add these lines to .travis.yml (note this are only two lines):
after_success:
- '[ "${TRAVIS_BRANCH}" = "stable" ] && git push https://${GITHUB_TOKEN}:[email protected]/${TRAVIS_REPO_SLUG}.git HEAD:master'
Now for some explanation: The first part, [ "${TRAVIS_BRANCH}" = "stable" ] &&
only runs the following command if the current branch name is "stable". You can omit this if you want to merge from ANY branch, or change it to use another branch.
The second part, git push https://${GITHUB_TOKEN}:[email protected]/${TRAVIS_REPO_SLUG}.git HEAD:master'
actually pushes the currently checked out state into master.
$GITHUB_TOKEN
holds our Token from above$TRAVIS_REPO_SLUG
holds github_username/github_repo_name
(in my case this is mhutter/mhutte.github.io
).To ensure new pages don't break Jekyll (as I managed earlier this month), I use Travis-CI.
I started working on a development branch and only merging into master after the Travis build succeeded. However, being the lazy guy I am I asked myself: "Wouldn't it be nice to let Travis automatically merge into master if the build succeeds?"
Next post: "Heredoc in Javascript"
Previous post: "Install own CA-Certificate in Linux"
List all Blog posts