Skip to content

Commit e37cb1a

Browse files
authored
[GitLab] Improve error handling for custom runner script (#62)
Fix: user script execution failure should be treated as build failure instead of system failure
1 parent 230859a commit e37cb1a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

GitLab/scripts/base.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ function valid_ip {
4646
return 255
4747
}
4848

49+
# https://docs.gitlab.com/runner/executors/custom/#build-failure
50+
function build_failure {
51+
exit "$BUILD_FAILURE_EXIT_CODE"
52+
}
53+
54+
# https://docs.gitlab.com/runner/executors/custom/#system-failure
4955
function system_failure {
5056
if [ $? -eq 28 ]; then
5157
echo "Curl operation timed out. Exiting..."

GitLab/scripts/run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ IFS=';' read -ra info <<< "$connection_info"
1313
vm_ip=${info[0]}
1414
vm_ssh_port=${info[1]}
1515

16+
# Treat failure of user script execution as build failure instead of system failure
17+
trap - ERR
18+
1619
ssh -i "$ORKA_SSH_KEY_FILE" \
17-
-o ServerAliveInterval=60 -o ServerAliveCountMax=60 "$ORKA_VM_USER@$vm_ip" -p "$vm_ssh_port" /bin/bash < "${1}"
20+
-o ServerAliveInterval=60 -o ServerAliveCountMax=60 "$ORKA_VM_USER@$vm_ip" -p "$vm_ssh_port" /bin/bash < "${1}" || build_failure

0 commit comments

Comments
 (0)