Troubleshooting


Error Handling

If a command can fail wrap it in if

Otherwise it will break the job/pipeline

job_name:
  script:
  - |
    if ! command; then
        echo "ERROR: Failed to run command."
        false
    fi

Use command || true is dangerous because it hides errors

(Let’s not talk about readability of bash )


Shotgun debugging

Adding many echo stagements is the most prominent (and hated) approach

Better add regular output to the script blocks…

…especially when using multi-line commands

Add output to both branches of if-then-else statements

Consider moving commands to a script file…

…this can enable local debugging


Testing locally

gitlabci-local

Run whole pipelines locally using gcil (formerly gitlabci-local)

Supports shell and Docker executor

Runs one or more jobs or even the whole pipeline

gitlab-runner

This is deprecated and was removed in GitLab 17.0

Test a single job using Docker using gitlab-runner :

gitlab-runner exec docker <job_name>

Works for more executors: shell, ssh, docker-ssh and more!