Skip to content

Support environment keyword with trigger keyword

Shinya Maeda requested to merge support-environment-keyword-in-bridge-jobs into master

This MR is built on top of Support environment predefined variables in job... (!128694 - merged)

What does this MR do and why?

This MR introduces a support for environment keyword to be combined with trigger keyword (a.k.a. downstream pipelines).

It's a very simple change that moving the environment config entry to the processable superclass, so that it supports both build and bridge job types. Nevertheless, good amount of integration tests are added so that we can verify that the feature works in various configurations.

All of the fundamental works have already been done in the previous MRs, which you can see in the main issue Support `environment` keyword with `trigger` ke... (#369061 - closed).

Screenshots or screen recordings

Peek_2023-08-22_15-35

How to set up and validate locally

  1. Enable support_ci_environment_variables_in_job_rules feature flag.
  2. Activate EEU license in the GitLab instance.
  3. Create upstream and downstream projects.
  4. Add following .gitlab-ci.yml in the downstream project.
    provisioning:
        script: export
        rules:
          - if: $CI_PIPELINE_SOURCE == "pipeline" && $UPSTREAM_ENVIRONMENT_ACTION == "start"
    
    teardown:
        script: export
        rules:
          - if: $CI_PIPELINE_SOURCE == "pipeline" && $UPSTREAM_ENVIRONMENT_ACTION == "stop"
  5. Add following .gitlab-ci.yml in the upstream project.
    stages:
        - deploy
        - cleanup
    
    .downstream-deployment-pipeline:
        variables:
            UPSTREAM_PROJECT_ID: $CI_PROJECT_ID
            UPSTREAM_ENVIRONMENT_NAME: $CI_ENVIRONMENT_NAME
            UPSTREAM_ENVIRONMENT_URL: $CI_ENVIRONMENT_URL
            UPSTREAM_ENVIRONMENT_ACTION: $CI_ENVIRONMENT_ACTION
            UPSTREAM_ENVIRONMENT_TIER: $CI_ENVIRONMENT_TIER
        trigger:
            project: multi-project-deployment-pipelines/downstream-project
            branch: main
            strategy: depend
    
    deploy-review:
        stage: deploy
        extends: .downstream-deployment-pipeline
        environment:
            name: review/$CI_COMMIT_REF_SLUG
            on_stop: stop-review
    
    stop-review:
        stage: cleanup
        extends: .downstream-deployment-pipeline
        environment:
            name: review/$CI_COMMIT_REF_SLUG
            action: stop
        when: manual
  6. Make sure the upstream pipeline runs correctly and triggers the downstream pipeline.
  7. Make sure the downstream pipeline has deployment context such as UPSTREAM_ENVIRONMENT_NAME.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Shinya Maeda

Merge request reports

Loading