Add the following job to your .gitlab-ci.yml
to add a manual "Play" button to deploy to production.
We're still dealing with "continuous delivery", not "continous deployment", so we'll only push changes to production after our (pretend) Change Control Board give us the thumbs up following successful testing in the Stage/UAT environment (see next slide):
deploy_to_prod:
tags:
- shell
stage: deploy
environment: production
when: manual
script:
- GIT_SSH_COMMAND="ssh -i ~gitlab-runner/.ssh/push_to_git" git push --force git@gitlab.example.com:root/www.git +HEAD:refs/heads/prod
Explanation of the git command:
GIT_SSH_COMMAND="ssh -i ~gitlab-runner/.ssh/push_to_git" git push --force git@gitlab.example.com:root/www.git +HEAD:refs/heads/prod
- GIT_SSH_COMMAND to specify SSH command line options (such as
-i
to specify identity file) --force
override built-in safeguards (seegit-push
man page if you want details)+
tells git to create the target branch if it doesn't existHEAD:ref/heads/prod
means theHEAD
(tip) of theprod
branch