Skip to content

Introduce new custom executor build exit code

  • Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA

What does this MR do?

This effort introduces optional behavior to the BUILD_FAILURE_EXIT_CODE that aims to allow user of the custom executor to capture the real exit code. When the BUILD_EXIT_CODE_FILE is created the GitLab runner will retrieve the supplied exit code for the underlying build failure. The primary goal of this is to allow jobs to leverage the allow_failure:exit_codes feature in conjunction with a custom executor.

One important note regarding this solution, I feel the strategy of providing details back to the runner via file is the safest option and removes any risk of breaking existing implementations and does not conflict with any existing workflows.

Potential Area for Further Refinement

The BUILD_FAILURE_FILE_EXIT_CODE and other related variable are very similar to the existing BUILD_FAILURE_EXIT_CODE variable.

Why was this MR needed?

Currently there is no way for the custom executor to return the underlying build error as the runner only observes exit code 1 as a build failure.

What's the best way to test this MR?

Setting up a custom executor with a simple run script and creating test jobs that exits with different codes and including the allow_failure option:

[[runners]]
  name = "test custom runner"
  url = "https://gitlab.com"
  executor = "custom"
  builds_dir = "/home/user/.gitlab-runner"
  cache_dir = "/home/user/.gitlab-runner"
  [runners.custom]
    run_exec = "/home/user/.gitlab-runner/run.bash"

The run.bash script could look something like:

#!/bin/bash

bash -c ${1}
code=$(echo $?)

if [ $code -ne 0 ]; then
    echo $code > ${BUILD_EXIT_CODE_FILE}
    exit ${BUILD_FAILURE_EXIT_CODE}
fi

What are the relevant issue numbers?

close #37910

Edited by Paul Bryant

Merge request reports

Loading