Skip to content

Instantly share code, notes, and snippets.

@bumi
Last active December 18, 2015 18:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumi/5824548 to your computer and use it in GitHub Desktop.
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
#!/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