Did you know that you can add your own favorite Drush commands to your Pantheon environments? You can! I have been asked this question several times as a Customer Success Engineer, so making this process available to everyone seemed to make sense.
While we have the full spectrum of drush core already available for your use, you may have a command that you regularly use that you’d like to add, for instance, Drush search and replace (sar). You may have even written your own custom command(s) or aspire to.
NOTE: As a best practice, you will need to update to Drush 7 locally. You must also create a policy file in order for Drush 7 to be invoked on Pantheon since, at this time, the default version is Drush 5.
Chances are that if you are on the path to adding your favorite Drush commands that you have already configured your local machine to run your Drush commands on your Pantheon environments, but if not—it’s well worth the effort to set it up!
Now, in order to get the Drush command you want to add into your codebase, follow the steps below:
1. Put site in Git mode
2. Clone locally
3. Create “drush” folder in Drupal root.
4. Add “sar” Drush command to “drush” folder.
5. Commit drush/sar
6. Push your code up to master.
7. Deploy to Test and Live.
8. Download your Pantheon Drush aliases (see Drush Aliases Available).
9. Clear your Drush cache on each environment (example: “drush @pantheon.<site-name>.devcc drush” ) .
The Perfect Website Launch
Note: If you have successfully set up Terminus, the Pantheon CLI, you can obtain your Drush aliases by using “terminus sites aliases”. For more details, please visit our Support Document on Drupal Drush.
At this point, your added Drush command should be ready to use. Remember, Drush 5 is the default version for newly created sites on Pantheon. You need to be running Drush 7 in order for the steps outlined in this article to work. See Greg’s post on creating a Policy File.
Now that you know how to customize Drush on Pantheon, take advantage of it! Hosting on a tightly structured platform gives you the stability you need to maintain uptime and to keep Drupal running optimally, but hopefully, you will also take advantages of ways you can tailor your development experience on Pantheon by adding some personal touches.
Thanks to Greg Anderson for his contributions to this article!
Additional Drush resources you may want to explore and/or bookmark:
Topics: Website Technology, Development, Drupal