Make it possible to control build status using exit codes
Update
We've open a separate issue #273157 (closed) to explore additional ways on how to solve this issue - Please add your comments to this issue only if the proposed solution does not fit your needs
Description
It may be an interesting feature to be able to control build status using .gitlab-ci.yml
and exit codes.
Proposal
Implement control for exit codes as follows, based on the list of possible ones that are supported (failed, warning, success):
my-job:
script:
- echo Hello world!
script_exit_codes:
success: [0, 1, 2]
warning: [7, 14]
canceled: [8]
# anything else is failed
script_exit_codes
are applied to the job based on the first non-zero exit code encountered in the script, or the last zero if all exit codes were zero.
- If
success:
is not defined, it is evaluated assuccess: [0]
. If it is defined, and you want 0 to be a success, it must be included in your array. - If
warning:
is not defined, it is evaluated aswarning: []
- If
canceled:
is not defined, it is evaluated ascanceled: []
- If a job is set to
allow_failure: true
, all failure states will be also treated as warnings.
Invalid configurations:
The following configuration should be considered invalid and a syntax error should be returned because of duplicate values (1
in this case). Both success
and warning
should have mutually exclusive values.
my-job:
script:
- echo Hello world!
script_exit_codes:
success: [0, 1, 2]
warning: [1]
References
It would be used by https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8121
Idea from @ayufan during Slack conversation :)
Sequencing
- Add
script_exit_codes
to the YAML keywords - Include
script_exit_codes
in the/request
jobs response - Add support for
canceled
state. This should already be done as part of gitlab-runner#4843 (closed) - The runner should compare the exit code with the ones defined in
script_exit_codes
(if available) before sending the status.
This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.