Skip to content

Commit 698e6bf

Browse files
mads-hartmannroboquat
authored andcommitted
Pass the SIGNAL to cleanup to improve logging
1 parent 2d50f74 commit 698e6bf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

.werft/workspace-run-integration-tests.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ BRANCH="wk-inte-test/"$(date +%Y%m%d%H%M%S)
66
FAILURE_COUNT=0
77
RUN_COUNT=0
88
declare -A FAILURE_TESTS
9+
declare SIGNAL # used to record signal caught by trap
910

1011
context_name=$1
1112
context_repo=$2
1213

1314
function cleanup ()
1415
{
15-
werft log phase "slack notification" "slack notification"
16+
werft log phase "slack notification and cleanup $SIGNAL" "Slack notification and cleanup: $SIGNAL"
17+
1618
werftJobUrl="https://werft.gitpod-dev.com/job/${context_name}"
1719

1820
if [ "${RUN_COUNT}" -eq "0" ]; then
@@ -39,14 +41,17 @@ function cleanup ()
3941
BODY="{\"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"${title}\"},\"accessory\":{\"type\":\"button\",\"text\":{\"type\":\"plain_text\",\"text\":\":werft: Go to Werft\",\"emoji\":true},\"value\":\"click_me_123\",\"url\":\"${werftJobUrl}\",\"action_id\":\"button-action\"}}]}"
4042
fi
4143

44+
echo "Sending Slack notificaition" | werft log slice "slack notification"
4245
curl -X POST \
4346
-H 'Content-type: application/json' \
4447
-d "${BODY}" \
4548
"https://hooks.slack.com/${SLACK_NOTIFICATION_PATH}"
4649
werft log result "slack notification" "${PIPESTATUS[0]}"
50+
werft log slice "slack notification" --done
4751

48-
werft log phase "clean up" "clean up"
4952
git push origin :"${BRANCH}" | werft log slice "clean up"
53+
54+
echo "Finished cleaning up based on signal $SIGNAL" | werft log slice "clean up"
5055
werft log slice "clean up" --done
5156
}
5257

@@ -70,7 +75,11 @@ werft log phase "build preview environment" "build preview environment"
7075
werft run github -a with-preview=true
7176
) | werft log slice "build preview environment"
7277

73-
trap cleanup SIGINT SIGTERM EXIT
78+
for signal in SIGINT SIGTERM EXIT; do
79+
# shellcheck disable=SC2064
80+
# We intentionally want the expansion to happen here as that's how we pass the signal to the function.
81+
trap "SIGNAL=${signal};cleanup" $signal
82+
done
7483

7584
# Our current approach will start two Werft jobs. One triggered by Werft by the push to the branch and one
7685
# due to the `werft run` invocation above - the manual invocation is needed as we don't enable preview

0 commit comments

Comments
 (0)