Composer: save the output to a file

For a while now, at Silicon, we use a combination of Capistrano and Composer to deploy our websites and other services we created.

We tried many possibilities, the one we choose is to run composer install on every deployment. But that means that a dependancy (plugin or theme) can be updated during the deployment.

Of course, it’s not perfect, in an ideal world, we would have a staging server to test and validate the deployment, but it’s not the case. So, to keep a track of Composer’s updates during deployment, I had the idea to mail the output of Composer after the end of the deployment. For doing that, I need to store Composer output in a file and, only if the deployement was successful, send the email with the content of this file.

Simple Linux command to run in your cap deploy:

But funny was that the file was empty.

I didn’t find the information on the web, but @ethanol on freenode IRC #composer gave me the reason:

most output goes to stderr

So finally, if you want to save the output to a file, don’t forget to catch stderr with something like:

Published by

Constantin Guay

Currently Data Project Manager and Scrum Evangelist at NetMediaEurope, european leader in IT B2B news site (more than 12 million unique visitors per month). Passionate by user experience and data science. Scrum evangelist

Leave a Reply

Your email address will not be published. Required fields are marked *