Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • gitlab-runner gitlab-runner
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 2,506
    • Issues 2,506
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 122
    • Merge requests 122
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • gitlab-runnergitlab-runner
  • Issues
  • #25394
Closed
Open
Issue created Aug 09, 2016 by Greg Dubicki@gdubicki

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