CI/CD only with some requirements

Hello Community,

I’m absolutely new in CI/CD for this case. In the follow I try to describe my scenario at the best. Maybe someone can help me with an gitlab-ci.yaml example.

Scenario:

  • Production Server (prod.foo.bar, SSH, kickstarter.sh script which pulling the newst production branch changes)
  • Branch: master (Developer push their code in here, or from feature-branches MR’s)
  • Branch: production (protected, only MR from master → production is possible)

So good, so far. How can I code it into a gitlab-ci.yaml with the following requierements?

MR from master to production → all is fine and approved → after approving merge is started → after merge is complete the ci should go ahead and execute the kickstart.sh script on the prod-server

The CI script should running from the production realm (not from master) and only when the MR (master → production) is approved and done.

Can someone help me in this case?

1 Like

Normally I would setup a gitlab-runner in the production environment.
This runner should have a tag (like “production”), run only tags (so no untagged jobs can run on that runner). Probably you also want to add that it can only run for protected branches and that you actually add the project to that runner and let it only run for that project.

for your ci file you then setup something like:

deploy:production:
stage: deploy
script:
- bash kickstart.sh
only:
- production #(only execute for your production branch)
tags:
- production #( make sure this is picked up by your runner in your production environment)

1 Like

Thanks barj, I’ll test this asap.