Skip to content
GitLab
Next
    • Why GitLab
    • Pricing
    • Contact Sales
    • Explore
  • Why GitLab
  • Pricing
  • Contact Sales
  • Explore
  • Sign in
  • Get free trial
  • GitLab.orgGitLab.org
  • gitlab-runnergitlab-runner
  • Issues
  • #25394

Gitlab CI script doesn't pass exit code of previous command properly

Example gitlab-ci.yml:

build_1:
  script:
    - false && true
    - echo $?

Current build result:

gitlab-ci-multi-runner 1.3.2 (0323456)
Using Shell executor...
Running on gitlabci-runner03...
Fetching changes...
HEAD is now at 9f64dee Test commit
From https://myserver/gdubicki/gitlab-ci-test
 * [new branch]      test-false-and-true -> origin/test-false-and-true
Checking out 810aa8c5 as test-false-and-true...
$ false && true
$ echo $?
0

Build succeeded

Expected build result:

like above but echo $? should print 1 instead of 0.

Proposal

  • This functionality needs a feature flag.

  • Implement CheckForErrors() for the BashWriter, this would need to be called in Command(). Something like:

    func (b *BashWriter) CheckForErrors() {
    	b.Line("_runner_exit_code=$?; if [[ $_runner_exit_code -ne 0 ]]; then exit $_runner_exit_code; fi")
    }
  • Remove set -eo pipefail as a default option.

This means script commands do not rely on the set -e mechanism, but also means that subshells will no longer automatically get the set -eo pipefail behaviour.

We do not solve the problem of $? being overwritten by echo statements we add for debugging, but try to side-step the issue by offering a more consistent way of exiting on failure.

Edited Sep 17, 2020 by Tomasz Maczukin
Assignee
Assign to
Time tracking