A few weeks ago I was trying to update a side project's CircleCI config from version 1 to version 2 since they are depreciating V1 in August 2018. In the process, I was curious how I could deploy specific branches to specific environments in Laravel's Envoyer if the tests passed successfully.
My project has two main branches:
master. In Envoyer I have two projects, one for
dev.project.com which uses the
develop branch and the other for
project.com which uses the
Here is the final result of the
circle.yml file. Let's work through each of the sections below.
Section 1: Defaults
By leveraging YAML anchors we can set a group of defaults that will be used for all of our later jobs. For now, this includes our
chosen CircleCI docker image
Section 2: Jobs
In this file we have three jobs:
build (and test),
Imports the defaults
Sets environment variables
Checks out the repo's code
composercache, if available
Saves a new
Runs the test suite with PHPUnit
Our "deploy" jobs:
Imports the defaults
Pings Envoyer to deploy the project
Section 3: Workflows
Now that we have our jobs set up, we need to implement workflows to pull everything together. Workflows are optional, but they can come in handy depending on what you'd like to do with your project.
In this example, we only need one workflow
notify_deploy which will notify Envoyer that we want to deploy a specific branch.
Within the workflow, you'll notice that we are listing all of our jobs:
We start off running our
build job, and if that is successful, we'll move forward with our deploy jobs. Each deploy job requires the
build to run first; then we'll check if the version branch matches the filter on the workflow. So
deploy_develop is only run on the
develop branch and
deploy_master is only run on the
By limiting the filters to only the
master branches we can guarantee that we're only deploying those specific branches, but the
build job will run on all branches (bug, hotfix, and feature branches), which is needed for pull requests.
Once we merge a branch into either
master CircleCI will build and notify Envoyer to deploy if successful. In our CircleCI dashboard, you'll now see a workflow similar to this.
You'll also need to make sure you turn off the "Deploy When Code Is Pushed" option in your Enoyer project.
This is only scratching the surface of what you can do with CircleCI builds and workflows. I encourage you to look through the documentation and example projects to see what you can implement in your projects.
Please note - CircleCI nor Envoyer/Laravel paid me to write this article, I'm just a happy customer.