Skip to content

Commit a5b6b6d

Browse files
committed
Update artificial traffic job to delete the preview after job's completion
Signed-off-by: ArthurSens <[email protected]>
1 parent 258b832 commit a5b6b6d

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

.werft/platform-trigger-artificial-job.sh

+29-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ sudo chown -R gitpod:gitpod /workspace
1515
git config --global user.name roboquat
1616
git config --global user.email [email protected]
1717

18-
git checkout -b "platform-artificial-job-$(echo $RANDOM | md5sum | head -c 20; echo;)"
18+
BRANCH="platform-artificial-job-$(echo $RANDOM | md5sum | head -c 20; echo;)"
19+
git checkout -b "$BRANCH" | werft log slice "Creating new branch"
1920

20-
werft run github -a with-preview=true
21+
BUILD_ID=$(werft run github -a with-preview=true)
22+
job_url="https://werft.gitpod-dev.com/job/${BUILD_ID}"
23+
echo "Triggered job $job_url" | werft log slice "Triggering new job"
24+
werft log result -d "build job" url "$job_url"
25+
26+
while true; do
27+
job_phase=$(werft job get "${BUILD_ID}" -o json | jq --raw-output '.phase')
28+
if [[ ${job_phase} != "PHASE_DONE" ]]; then
29+
echo "Waiting for ${BUILD_ID} to finish running. Current phase: ${job_phase}. Sleeping 10 seconds." | werft log slice "Waiting for job completion";
30+
sleep 10
31+
else
32+
echo "Phase reached ${job_phase}. continuing." | werft log slice "Waiting for job completion";
33+
break
34+
fi
35+
done
36+
37+
###########
38+
# Deleting artificial preview
39+
###########
40+
41+
werft log phase "Deleting artificial preview" "Deleting artificial preview"
42+
43+
preview=$(previewctl get-name)
44+
DELETE_JOB_ID=$(werft run github -j .werft/platform-delete-preview-environment.yaml -a preview="$preview")
45+
delete_job_url="https://werft.gitpod-dev.com/job/${DELETE_JOB_ID}"
46+
echo "Triggered job $delete_job_url" | werft log slice "Triggering new job"
47+
werft log result -d "delete preview job" url "$delete_job_url"

0 commit comments

Comments
 (0)