Pre/Post deployment commands for CodeDeploy?

circle.yml

#1

Hey all!

I’d love to be able to run a command before/after a CodeDeploy deployment (database migrations and the like) so that they’re only run once. Is this possible at all?


#2

Hey Nathaniel, we chatted a bit about this at CircleCI Office Hours. I’ll make sure to bring it to the attention of the engineer that did the CodeDeploy feature.


#3

@anon52070816 dude, you’re awesome! thanks again for talking with me then!


#4

Sorry I was silent on this for a while. I’m afraid the best workaround I can offer at the moment is that the test:post phase is fairly close to being deployment:pre, but it’s not exactly what you’re looking for. It is definitely in our medium/long-term roadmap to make the baked-in deployment options like CodeDeploy more extensible.


#5

That is a-okay man! Glad to hear it and thanks for listening!


#6

Another vote for this functionality. We use CodeDeploy to deploy Clojure apps, and we’d love to be able to only build the uberjar when we are doing a deploy, rather than after every test run. (Your CodeDeploy docs suggest that CodeDeploy’s lifecycle hooks can be used instead of pre: and post:, but we’d prefer to build the uberjar on the Circle VM, not the destination box.)


#7

To have pre and post hooks for the deployment section would be ideal, or allow multiple deployment destinations. For example as part of a deployment, an app I manage pushes images to a docker repository and the managing code through CodeDeploy. Perhaps the suggestion would be to split these builds / repos up, but that isn’t always ideal. Is a good workaround to have these ‘pre’ deployment tasks run as additional commands during the test ‘override’ stage?


#8

I need this feature as well in order to process static assets before the deployment is initiated.


#9

Totally agree. I’m using CodeDeploy with a Rails app and would really like to have a clean solution for running my migrations from a single place once the new code is in place.


#10

Any update on this? This is a must have for us.


#11

+1 for this!! I’m using codedeploy. But, I’d like to create the builds before calling codedeploy, buy AFTER successful tests.


#12

Hello, any news on this?

I would like to send a slack notification that a deployment will start and I also can’t, and that is really frustrating


#13

Hello all,

Thank you for your interest in this feature.

I wil move this "feature requests"category and make sure our product team knows about it.


#14

We are working around this by running a deployment script. In that script we are checking for an environment variable PRE_COMMAND and POST_COMMAND. If it exists we run the command set in those variables.

Example code:

if [ "${CIRCLE_BRANCH}" = 'master' ] && [ -n "${MASTER_PRE_COMMAND}" ]; then
    echo "Running pre deployment command (${CIRCLE_BRANCH})"
    ssh username@${HOST} "${MASTER_PRE_COMMAND}"
fi

#15