Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple environments in same repo based on branches #42

Open
Antarpreet opened this issue Jan 17, 2024 · 1 comment
Open

Comments

@Antarpreet
Copy link

We are trying to set the value for the environment_type parameter dynamically using the following logic based on the branch being updated while keeping the value as one from the enum


- run:
        name: Set environment type
        command: |
            if [ "${CIRCLE_BRANCH}" == "main" ]; then
              export environment_type="production"
            elif [ "${CIRCLE_BRANCH}" == "staging" ]; then
              export environment_type="staging"
            elif [ "${CIRCLE_BRANCH}" == "dev" ]; then
              export environment_type="development"
            fi
- jira/notify:
        pipeline_id: << pipeline.id >>
        pipeline_number: << pipeline.number >>
        environment: $CIRCLE_BRANCH
        environment_type: $environment_type
        job_type: deployment

However, the workflow fails with the following error before the pipeline runs.

Type error for argument environment_type: expected type: enum ("production" "staging" "testing" "development" "unmapped"), actual value: "$environment_type" (type string)

This workflow triggers directly from GitHub when a new commit is pushed to one of the environment branches so we cannot add trigger parameters for each branch and environment separately.

What do you think is the best way to do this dynamically? Will it be possible to convert the environment_type parameter to a string type to prevent circleCI from stopping the pipeline from triggering?

@LeoAnt02
Copy link

LeoAnt02 commented Jan 30, 2024

Here's how we do it using conditional inside your job

your_job:
    parameters:
      environment:
        type: string
    steps:
      - when:
          condition:
            equal: [ << parameters.environment >>, "production" ]
          steps:
            - jira/notify:
                environment: << parameters.environment >>
                environment_type: production
                job_type: deployment
                pipeline_id: << pipeline.id >>
                pipeline_number: 11111
      - when:
          condition:
            equal: [ << parameters.environment >>, "staging" ]
          steps:
            - jira/notify:
                environment: << parameters.environment >>
                environment_type: staging
                job_type: deployment
                pipeline_id: << pipeline.id >>
                pipeline_number: 11111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants