User defined after_script is executed after failed pre_build_script and bypasses post_build_script

Summary

Situation: both pre_build_script and post_build_script is defined in config.toml, after_script is defined in .gitlab-ci.yml. When pre_build_script fails (i.e. I explicitly call exit 1), then user-defined after_script is executed and post_build_script is not executed at all. I consider it a bug.

I want to enforce some checks using pre_build_script and I expect that no user-defined script is run when pre_build_script exits with non-zero status.

Steps to reproduce

See above.

Actual behavior

Runner executes user-defined after_script when pre_build_script fails (e.g. exit 1).

Expected behavior

after_script should not be executed after pre_build_script failure, or should be executed after post_build_script.

GitLab Runner/Configuring GitLab Runner/Advanced configuration:

post_build_script – commands to be executed on the runner just after executing the build, but before executing after_script.

Relevant logs and/or screenshots

N/A

Environment description

docker+machine executor

Used GitLab Runner version

Version:      10.5.0
Git revision: 80b03db9893ab1668ac601909c1a1bf29d476035
Git branch:   10-5-stable
GO version:   go1.9.2
Built:        2018-02-22T21:19:46
OS/Arch:      linux/amd64

Customers

https://gitlab.my.salesforce.com/0014M00001pQxLq

https://gitlab.my.salesforce.com/00161000004bZxf

Edited by Manuel Grabowski