Skip to content

A GitLab job's script lines are one script; after_script cannot fail the job - #340

Open
leftibot wants to merge 1 commit into
cpp-best-practices:mainfrom
leftibot:gitlab-and-lines
Open

leftibot wants to merge 1 commit into
cpp-best-practices:mainfrom
leftibot:gitlab-and-lines

Conversation

@leftibot

Copy link
Copy Markdown
Collaborator

Part of #334: the GitLab gap left by #338.

What changes

GitLab Runner runs a job's before_script and script lines as one shell script that starts with set -eo pipefail. #338 judged each line as a script of its own, which missed two things:

  • a && b on a line that isn't the last. If a fails, errexit passes over it and the job goes on. On the last line, the failure ends the script with its status, so that line still counts.
  • set carries over. A set +e on one line holds for the lines after it, so a later command followed by others cannot fail the job.

Now the lines are judged in order. masked has a followed flag (more of the script comes after these commands) and a new after() that returns the shell options a script's set commands leave.

after_script runs in a shell of its own, and GitLab ignores its exit status. Its commands are now advisory: in after_script, whose failure GitLab ignores. A job's allow_failure still wins, as before.

A set command is never reported itself. glib's repository scripts open with set -eux -o pipefail, which runs before errexit is on, and #338 reported that set as masked. What set changes is the shell's options; it is no step whose failure matters.

On the corpus

On the five GitLab projects in the corpus (glib, cmake_template, cabal, kubespray, home-manager), no check result changes. The newly advisory commands, all of them correct, are:

  • kubespray: the after_script cleanup: log tarballs, vagrant destroy -f, tofu … destroy.
  • cmake_template: ln -snf … && echo $TZ > /etc/timezone in the middle of a script.

glib's set -eux -o pipefail lines are no longer reported.

Tests

  • GitLabTests in tests/test_masked_status.py: lines as one script, including before_script; set across lines; after_script.
  • SequenceTests.test_a_set_command_is_never_reported.
  • Each was RED before its change.

Gates: ruff, ruff format, mypy, lizard (30 lines), all 2,478 tests passing (13 expected failures), coverage 99% (100% on the changed files), 0 jscpd clones, strict self-validation. Snapshots are unchanged.

Not covered

PowerShell scripts, on Windows GitLab runners and in GitHub's pwsh, still aren't judged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

…the job

GitLab Runner runs a job's before_script and script lines as one shell
script that starts with `set -eo pipefail`. A command before && on any
line but the last cannot fail the job (errexit passes over it), and a
line's `set` holds for the lines after it. Each line was judged as a
script of its own, so neither was seen.

after_script runs in a shell of its own, and GitLab ignores its exit
status: its commands are advisory ("in after_script, whose failure
GitLab ignores").

A `set` command is never reported itself: glib's scripts open with
`set -eux -o pipefail`, which runs before errexit is on.

Part of cpp-best-practices#334

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.75%. Comparing base (d3dc4c2) to head (8e40ae3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #340   +/-   ##
=======================================
  Coverage   99.75%   99.75%           
=======================================
  Files         299      299           
  Lines       18136    18151   +15     
  Branches     2086     2090    +4     
=======================================
+ Hits        18092    18107   +15     
  Misses         44       44           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant