Development / Production environment circleci configuration

Hi, I’m wondering how one should deal with development and production environments when building and deploying applications with circleci.

The scenario is the folowing, I want to deploy a GCP Cloud run instance as such:
gcloud run deploy my-service --project $GCP_PROJECT

The workflow for production environment and development environment would be more or less the same, the only thing that would differ is the value of $GCP_PROJECT (and some other variables, but the use case is the same)

Is there a way where I can conditionally assign values in the same job in such cases? I want to avoid duplication inside the config so the config is more readable.

I’m aware about other features like branch filtering which enable me to differentiate between deploys to different environments, but I cannot find a way to avoid duplicating whole jobs just to assign different variables, like in the example below. Any suggestions on how to tackle deploying to different environments with as little duplication as possible?

The only way I see how I can achieve this right now is by using two virtually almost the same jobs and having multiple environment variables, as such:

            - run:
                  name: "My prod job"
                  command: gcloud run deploy my-service  --project $GCP_PROJECT

            - run:
                  name: "My dev job"
                  command: gcloud run deploy my-service  --project $GCP_PROJECT_DEV

However my fear is that this will become a complete mess with how much stuff actually needs to be duplicated.

Zdravo @jrepe :slight_smile:

You could add parameters for environment to your job - something like this:

                   type: string
                   default: $GCP_PROJECT_DEV
            - run:
                  command: gcloud run deploy my-service  --project << parameters.project_id >>

Then just pass the same job name with the desired parameter a workflow when you’re filtering branches or tags:

            project_id: 'your_project_id'

Relevant links:
Docs page: Reusable Config Reference Guide - CircleCI

We also recently released a quick video about them: Foundations: Parameterized Configuration - YouTube

Hope this helps!

I appreciate the quick response, this is exactly what I have been looking for. As a side not, ‘zdravo’ cought me completely off guard, not gonna lie :smile:

Thanks for the help!

1 Like