Environments¶
Goal
Learn how to...
- use environments to specify deployment targets
- select environments dynamically
Preparation¶
Create CI variables for use in the following exercises:
- Retrieve passwords for dev and live environments from the info page
- Create unprotected but masked CI variable
PASS
twice with scopedev
andlive
- Create unprotected CI variable
SEAT_INDEX
with your seat number
Task 1: Add target environment¶
Add a new stage deploy
with a job called deploy
and use the following commands to upload the binary to the dev environment:
curl https://seat${SEAT_INDEX}.dev.webdav.inmylab.de/ \
--fail \
--verbose \
--upload-file hello \
--user seat${SEAT_INDEX}:${PASS}
Mind that curl
is not available in the default image golang:1.19.2
but must be installed using the following commands. Apply what you learned about script blocks as well as separating commands into preparation, core steps and cleanup.
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run and be able to download the hello
binary from https://seatN.dev.webdav.inmylab.de/hello
.
Hint (Click if you are stuck)
Install curl
in a before_script
to separate the preparation from the core steps:
Now place the curl
command under script
.
Solution (Click if you are stuck)
.gitlab-ci.yml
:
If you want to jump to the solution, execute the following command:
Task 2: Add deployment to development environment¶
Create a new branch dev
from the branch main
and modify the job deploy
to use the environment from the pre-defined variable $CI_COMMIT_REF_NAME
. Mind that the upload URL is also using a hard-coded environment name.
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run.
Solution (Click if you are stuck)
If you want to jump to the solution, execute the following command:
This was just a demonstration. The changes will not be preseved in the following chapters.
Task 3: Add deployment to production environment¶
Create the branch live
from the branch dev
and push it without further changes.
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run and be able to download the hello
binary from https://seatN.live.inmylab.de/hello
.
Heads up
Checkout the branch main
to make sure that the following exercises are based on the correct code base.