¿Buscando una versión en Español?
Why Bash scripts?
You'll notice in the sample projects I put all the commands in Bash scripts. Why is that? It gives us 2 things.
- It allows us to run the commands locally (ie
./build.sh) - It makes your CI more portable. Almost any CI system can run bash scripts. The difference between GitHub and GitLab is just in how we tell the system which script to run and when.
New to Bash?
I chose Bash because I am familiar with it (more than PowerShell) and because it is cross-platform. If you are getting started, I recommend purchasing this cheatsheet. The biggest takeaway is to make sure you add set -euo pipefail at the top of your bash scripts so the error handling and exit codes work correctly.
A Note On Variables
In the GitLab examples, you'll notice this line:
. <(sed -nr '/variables:/,$ s/ ([A-Z_]+): (.*)/\1=\2/ p' vars.yml)
What this line does is that it reads in the vars.yml file and takes the variables section and sets the variables there as environment variables. This is so we can define the variables once and use them when running locally or on the CI server (this file is included in the .gitlab-ci.yml file). The sed command is kind of black magic but it works. I got it here: https://unix.stackexchange.com/questions/539009/export-environment-variables-parsed-from-yaml-text-file