In this post, I am going to show you how to prevent a release from being deployed directly to production if it hasn’t been deployed to staging. Octopus has a great feature called ( Lifecycles ) that allows you to create advanced deployment workflows for any type of project.
This way you are able to force your team to follow a strict deployment process that will definitely improve your test routine and the way how you deploy code changes. No more untested code changes on production!
Okay, let’s start. Here is how you can create a custom Lifecycle.
- From the Lifecycle page, click on the ADD LIFECYCLE button.
- Give the Lifecycle a name and add a description. For example ” Project X “.
- You can leave the Retention Policy unchanged ( Keep all ) for now.
Scroll down and continue with the next tab.
- Click ADD PHASE, to explicitly define the phases of the lifecycle.
- Give the phase a name. For example ” Staging ” because I want you deploy and review your changes on staging first.
- Click ADD ENVIRONMENT to define which environments can be deployed to during this phase of the lifecycle. Choose your staging environment from the dropdown list.
If you haven’t add an environment yet, you must create at least two ( staging, production ). Learn more about Environments.
Scroll up again and save the new Lifecycle. Now go back to your project and click the link Process in the left sidebar. Next, hit the button Change on the right-hand side and select the Lifecycle that you’ve just created and save the changes.
After that, try to deploy a new release. You will see that there is no option to deploy on production. Just must deploy your code successfully to your staging environment first in order to be able to push changes to production.
This is just one of many examples of how you can improve your deployment routine with Octopus.
I saw a few comments on Stackoverflow where people ask how to setup or re-enable deployment buttons for staging or production. The answer is not quite straightforward, because you have to review a few things. Here is a quick checklist that may help you to identify the cause of missing deployment buttons.
Make sure you have selected the right Lifecycle in Projects > Your Client > Deployments > Process.
If you believe one Phase / Environment missing, go to Library > Lifecycles and try to add the missing environment in the Phases section.
In order to be able to add a new phase, make sure all required environments are listed in Infrastructure > Environments.
Learn more about Environments.
I am pretty new to Octopus and just started implementing a deployment process for a new PHP project. After creating a new machine in Infrastructure > Deployment Targets I went back to Projects > My Project > Create Release and tried to start a deployment to our dev environment which caused the following error.
There must be at least one enabled healthy machine to deploy to in the environment, or the Project Deployment Target settings must be set to allow deployments to empty environments. Once you have corrected these problems you can try again. If the problem is related to a variable you will need to update the variables for this release or recreate the release for the changes to take effect. If the problem is related to the deployment process you will need to create a new release for the changes to take effect.
As you can see in the below screenshot, I tried to deploy a new release to the target Development.
The error message was strange because the target status of my Deployment Target was flagged as healthy. After comparing the settings I noticed that the environment Development in my deployment target settings was simply missing.
After adding the target Development to the list of Environments, I was able to proceed with the above deployment.