Skip to content

Instantly share code, notes, and snippets.



Last active Jul 25, 2016
What would you like to do?
Template for integrating Travis-CI and Pantheon Multidev
language: php
# Important to note, this is the version of PHP used to run this build, not the
# one used to run your Drupal installation. Ensure compatibility with the Drush
# and Terminus versions you're using for this build.
- 5.3
# Travis/Pantheon integration requires an RSA key that at least has read access
# to your GitHub repo and write access to Pantheon's git repo. Create a user on
# both systems with the most restricted access, given the aforementioned
# constraints. Then, for the given user, generate and load a public key to both
# GitHub/Pantheon. Follow instructions from Travis-CI on using this new key.
# Keep the Pantheon account e-mail address and password handy, you'll need it
# below in
source_key: INSERT_KEY_HERE
# Your Pantheon site's UUID (e.g. from your dashboard URL)
- PUUID='aaaaaaaa-0000-bbbb-1111-cccccccccccc'
# Your Pantheon site's name.
- PNAME='site-name'
# The Pantheon environment name from which Multidev DB/files will be pulled.
# Probably one of: dev, test, live.
- PSOURCE='test'
# PEMAIL environment variable: represents the Pantheon account e-mail with
# access to this site. Used to authenticate to Pantheon via Terminus. You
# must cd to your project root and run:
# travis encrypt PEMAIL='' --add
# Which will eventually look something like the key below.
# See:
- secure: "encrypted_email_value_here"
# PPASS environment variable: represents the Pantheon account password for
# the above encrypted e-mail address. Run:
# travis encrypt PPASS='my_account_password' --add
- secure: "encrypted_password_value_here"
# Generate a random branch / multidev name, prefixed with "ci" followed
# by the Travis build number. Note, due to Pantheon multidev environment
# name limits, builds will start failing at #100000.
- PSITE=$(cat /dev/urandom | tr -cd 'a-z0-9' | head -c 4)
# You can use $PHOST as a reference to the resulting multidev hostname.
- PHOST="https://$PSITE-$"
# Dynamic hosts through Pantheon mean constantly checking interactively
# that we mean to connect to an unknown host. We ignore those here.
- echo "StrictHostKeyChecking no" > ~/.ssh/config
# Install Drush.
- composer global require drush/drush:6.2.0
- export PATH="$HOME/.composer/vendor/bin:$PATH"
# Install Terminus.
- git clone $HOME/.drush/terminus
- cd $HOME/.drush/terminus
- composer update --no-dev
- drush cc drush
# Install additional test dependencies here (like Casper, Behat, etc).
# Authenticate with Pantheon via Terminus.
- drush pauth $PEMAIL --password=$PPASS
# Add Pantheon as a remote to our repo and force push to it.
- git checkout -b $PSITE
- git remote add pantheon ssh://$$
- git push --force pantheon $PSITE
# Create a new Pantheon environment using the above branch.
- drush psite-ecreate $PUUID $PSITE --source=$PSOURCE || true
# Update our drush aliases file.
- drush paliases
- drush cc drush
# We cannot be in a Drupal directory to run aliased drush commands.
- cd $HOME
# When new modules are added to the codebase, updb can sometimes fail (thus
# causing a failed build) because the system table and modules are out of
# sync. We get around this by clearing all caches before attempting anything.
# The "|| true" works around issues where Views and Block conflict during
# cache clears / block rehashes.
- drush @pantheon.$PNAME.$PSITE cc all --strict=0 || true
# Run all available updates as if deploying. For now, append the
# --strict=0 option for Drush 6.x compatibility on Pantheon.
- drush @pantheon.$PNAME.$PSITE updb -y --strict=0
# Enable additional test dependencies here, like SimpleTest.
- drush @pantheon.$PNAME.$PSITE en simpletest -y --strict=0
# If you're using SimpleTest, you'll want to disable verbose logging. This
# ensures no false build failures from file write errors.
- drush @pantheon.$PNAME.$PSITE vset -y simpletest_verbose 0 --strict=0
# This is where you run your tests, be they SimpleTest, Casper, Behat,
# or otherwise. Here's a SimpleTest example. I've found that drush
# likes to exit with odd codes if you run multiple classes at once.
# You may have to run one class at a time.
- drush @pantheon.$PNAME.$PSITE test-run MyTestClass --strict=0
- drush @pantheon.$PNAME.$PSITE test-run MyTestClass2 --strict=0
# Destroy the Pantheon environment
- drush psite-edelete $PUUID $PSITE -y
# Delete the git branch we created.
- cd $TRAVIS_BUILD_DIR; git push pantheon :$PSITE
# Continuous delivery! Handy for advanced QA/UAT workflows.
# If this was a master branch build (as opposed to PR), and the build passed:
# Go ahead and push the changes up to the dev environment and "deploy."
- if [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST = 'false' ] ; then pushd $TRAVIS_BUILD_DIR && git push pantheon $PSITE:master && popd && drush @pantheon.$ updb -y --strict=0 ; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.