Bash library
The internal Bash library for CI Tools is used in all components but can be also used standalone if you are not using GitLab CI/CD with components.
CI Tools requires Bash 5 or newer.
Usage
To load the library simply execute the command:
source <( curl -s https://gitlab.com/xrow-public/ci-tools/-/raw/main/scripts/bootloader.sh ) [version]
Replace [version] with either a branch name like main, stable or a proper release version like 4.192.0.
source <(curl -s https://gitlab.com/xrow-public/ci-tools/-/raw/main/scripts/bootloader.sh) 4.192.0
Afterwards you can execute any function of the available modules, for example:
ci_helm_build_chart ./chart
dotenv loading
Loading the library automatically imports dotenv files from CI_PROJECT_DIR in
this order:
| Loading order | Source | Condition |
|---|---|---|
| 1 | .env | The file exists in CI_PROJECT_DIR. |
| 2 | .env.<environment> | CI_ENVIRONMENT_NAME is set; its first segment selects the file. |
| 3 | ENV_FILE | The GitLab file-type CI/CD variable is set. |
For example, CI_ENVIRONMENT_NAME=review/feature-123 loads .env.review. Use
GitLab environment scopes on ENV_FILE when different environments need
different protected overrides. The job log lists each repository filename or
the ENV_FILE variable when loaded, without exposing file contents or temporary
secret paths.
If CI_ENVIRONMENT_NAME is unset, environment-specific .env.* files are not
loaded. dotenv files use KEY=value assignments. The loader does not execute
shell expansion, substitutions, or commands. Keep files compatible with
dotenv conventions and
GitLab's dotenv file requirements.
Example:
deploy_review:
environment:
name: review/$CI_COMMIT_REF_SLUG
script:
- source <(curl -s https://gitlab.com/xrow-public/ci-tools/-/raw/main/scripts/bootloader.sh) stable
- ./deploy.sh
With .env, .env.review, and an environment-scoped ENV_FILE variable, later
files in the table take precedence over earlier dotenv files. Existing exported
variables, including GitLab job, project, and group CI/CD variables, take
precedence over every dotenv file. If the Bash compgen builtin is unavailable,
automatic dotenv loading is disabled with a warning so existing variables cannot
be overwritten accidentally.
How jobs interact with the bash scripting library?
Some components delegate business logic to bash scripts available via a common library in scripts/library.sh. Each individual pipeline reuses some parts of the library. Components are loading the library as a remote script source <(curl -s https://gitlab.com/xrow-public/ci-tools/-/raw/main/scripts/bootloader.sh). ci_lint_yaml is a function out of the library scripts/lib/lint.sh. By convention the prefix of the function lint indicates use and location of the function.
Example from templates/lint-yaml/template.yml:
lint:yaml:
script: |
source <( curl -s https://gitlab.com/xrow-public/ci-tools/-/raw/main/scripts/bootloader.sh ) stable
ci_lint_yaml