Last active
December 18, 2015 18:19
-
-
Save bumi/5824548 to your computer and use it in GitHub Desktop.
little script to be run after_success on Travis-CI to push to a configurable deploy branch. I'm using it to deploy successful builds with chef: if the master is green push the code to master_green. from there it get's deployed with chef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# HOWTO: | |
# copy this file to script/travis-deploy | |
# chmod +x script/travis-deploy | |
# add the following to your .travis.yml | |
# after_success: | |
# - "script/travis-deploy" | |
exit if ENV["TRAVIS_DEPLOY_PUSHED"] | |
# set defaults | |
ENV["TRAVIS_DEPLOY_SOURCE_BRANCH"] ||= "master" | |
ENV["TRAVIS_DEPLOY_TARGET_BRANCH"] ||= "master_green" | |
# make sure we only deploy the correct branch | |
if ENV["TRAVIS_BRANCH"] != ENV["TRAVIS_DEPLOY_SOURCE_BRANCH"] || ENV["TRAVIS_PULL_REQUEST"] != "false" | |
puts "no deployment for: #{ENV["TRAVIS_BRANCH"]} pull request: #{ENV["TRAVIS_PULL_REQUEST"]} job number: #{ENV["TRAVIS_JOB_NUMBER"]}" | |
exit(true) | |
end | |
# push from the source branch to the master branch | |
puts "pushing from #{ENV["TRAVIS_DEPLOY_SOURCE_BRANCH"]} to #{ENV["TRAVIS_DEPLOY_TARGET_BRANCH"]}" | |
`git config user.name Choco` | |
`git checkout #{ENV["TRAVIS_DEPLOY_SOURCE_BRANCH"]}` | |
`git push origin #{ENV["TRAVIS_DEPLOY_SOURCE_BRANCH"]}:#{ENV["TRAVIS_DEPLOY_TARGET_BRANCH"]}` | |
puts "DONE, have a great day!" | |
ENV["TRAVIS_DEPLOY_PUSHED"] = "true" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment