CI environment variable for determining if environment is available
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Release notes
Problem to solve
We use GitLab CI environments for running Review Apps for merge requests. Creating a review app is expensive in both time and infrastructure, most changes don't necessitate one, and our deployments require some variables to configure the created environment. so we have the deploy job as a manual one.
Currently, we have create and update as the same job, meaning that all deployments to the review app are manual. Ideally, creating a review app initially is manual, but any subsequent pushes to the MR once the environment has been created would be automatic. This can be accomplished by having separate review_app:create and review_app:update jobs, where create is manual and update is automatic. However, review_app:update fails if we haven't created a review app. We have it on allow_failure: true but this has caused confusion on the team, as in the most common case (an MR without a review app), it looks like there are warnings on the pipeline even though everything is working as expected.
Proposal
If there was a way to tell with environment variables that an environment exists, we could conditionally run review_app:update using rules so that it would only try to deploy if the environment exists.
I thought perhaps that the CI_ENVIRONMENT_NAME automatic environment variable might be usable for this, but it seems to be set purely by the existence of environment: name in the job, not by the existence of that environment itself.
Open to other solutions, but it seems to me like a predefined environment variable like CI_ENVIRONMENT_RUNNING=true could tell jobs if the CI_ENVIRONMENT_NAME has been started or not. That could be used in rules: to conditionally trigger review_app:update. I could see it being useful elsewhere as well, e.g. with prepared environments.
Intended users
User experience goal
The user should be able to conditionally run a CI job if an environment is running.