Is it possible to run a Gitlab CI pipeline using multiple gitlab releases or branches

I want to be able to have a pipeline that deploys a main branch to a test environment and then a versioned release to production.

The versioned prod env will only be have a newer versioned deployed once testing has been signed off.

I want to have a single pipeline that does this, that I can run on a schedule so that prod is always up to date with certificates etc.

I have tried to do something like the following, but this only runs the deploy:test and not the deploy:prod

  image: alpine:3.18
  stage: release
    - echo "this is the $CI_DEFAULT_BRANCH"
    - cat version.txt
      when: always

  image: alpine:3.18
  stage: release
    - cat version.txt
    - if: $CI_COMMIT_TAG == "v11.0.0"
      when: always

Is something like this possible with gitlab ci?

The rules in the deploy:prod job require a Git tag. Otherwise the pipeline is not running the job.

Some ideas below.

Automated Git tags as trigger event

One solution could be that the deploy:test job tags the version, and pushes the git tag to the server. This triggers a new pipeline which will match the rule to run the deploy:prod job.

Parent/child pipelines

An alternative can be pipeline triggers or parent/child pipelines. When deploy:test is successful, the trigger for a child pipeline runs the deploy:prod job. This will not need the Git commit rule filter.

Release tarball as indicator to deploy

If deploy:test should be run, and later, a manual Git tag should trigger the deploy:prod job in a 2nd pipeline, you would need a “signal” token. This could be a release tarball that is uploaded into the package registry, and then checked for availability in the deploy:prod job. If not existing, job bails out.

1st pipeline

  1. Runs deploy:test and things before

2nd pipeline
2. Some job or action that uploads a release tarball to registry e.g. after a git tag for a release

3rd pipeline
3. deploy:prod that downloads tarball, and does deployment actions

Thanks for your reply.

I can’t work out, in the parent child, how to have the child use a different branch to the parent job.

the parent job will use ‘main’ branch, but the child should used a tagged version, ‘v11.0.0’

Is that possible?

The child job can install git, and checkout the git tag manually to further do things from there.

Example for a Debian/Ubuntu image:

  - apt update && apt -y install git
  - git checkout $CI_COMMIT_TAG
  - … do something