feature:add notify jobs done status by webhook

This commit is contained in:
fumingwei
2024-02-04 11:53:54 +08:00
committed by 付明卫
parent 57dbca0d5b
commit c4e6ab1f70
2 changed files with 79 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ stages:
- build
- merge_build
- deploy
- notify
.build_tsg-buildimage:
script:
@@ -43,6 +44,17 @@ stages:
tags:
- tsg-os-builder-el8
.notify_jobs_done:
cache:
key: $CI_COMMIT_REF_SLUG-x86_64_COTS
paths:
- images/
script:
- chmod +x ./tools/notify-jobs-done.sh
- ./tools/notify-jobs-done.sh
tags:
- tsg-os-builder-el8
.build_tsg_vm_image:
cache:
key: $BUILD_OS_CACHE_KEY
@@ -68,7 +80,9 @@ stages:
- ls -lh images
- chmod +x ./tools/upload.sh
- ./tools/upload.sh
- TSG_OS_VERSION=$(basename images/*-ONIE.bin | awk -F '-x86_64' '{print $1}')
- rm -rf images/*
- echo $TSG_OS_VERSION > images/tsg-os-version.txt
tags:
- tsg-os-builder-el8
@@ -150,6 +164,16 @@ feature_branch_build_kvm_image_x86_64_COTS:
- /^rel-.*$/i
- /^update-.*$/i
feature_branch_notify_jobs_done_x86_64_COTS:
image: $BUILD_BASED_IMAGE_ROCKYLINUX8
stage: notify
extends: .notify_jobs_done
except:
- tags
- /^dev-.*$/i
- /^rel-.*$/i
- /^update-.*$/i
# develop_build_7400_mcn0:
# image: $BUILD_BASED_IMAGE_CENTOS7
# stage: build
@@ -234,6 +258,13 @@ develop_build_kvm_image_x86_64_COTS:
only:
- /^dev-.*$/i
develop_notify_jobs_done_x86_64_COTS:
image: $BUILD_BASED_IMAGE_ROCKYLINUX8
stage: notify
extends: .notify_jobs_done
only:
- /^dev-.*$/i
# testing_build_7400_mcn0:
# image: $BUILD_BASED_IMAGE_CENTOS7
# stage: build
@@ -318,6 +349,15 @@ testing_build_kvm_image_x86_64_COTS:
only:
- /^rel-.*$/i
testing_notify_jobs_done_x86_64_COTS:
image: $BUILD_BASED_IMAGE_ROCKYLINUX8
stage: notify
extends: .notify_jobs_done
variables:
ENABLE_NOTIFY_TESTING_JOBS_DONE: 1
only:
- /^rel-.*$/i
# rc_build_7400_mcn0:
# image: $BUILD_BASED_IMAGE_CENTOS7
# stage: build
@@ -402,6 +442,16 @@ rc_build_kvm_image_x86_64_COTS:
only:
- /^.*-rc.*$/i
rc_notify_jobs_done_x86_64_COTS:
image: $BUILD_BASED_IMAGE_ROCKYLINUX8
stage: notify
extends: .notify_jobs_done
variables:
ENABLE_NOTIFY_RC_JOBS_DONE: 1
only:
- /^.*-rc.*$/i
# release_build_7400_mcn0:
# image: $BUILD_BASED_IMAGE_CENTOS7
# stage: build
@@ -495,3 +545,14 @@ release_build_kvm_image_x86_64_COTS:
- tags
except:
- /^.*-rc.*$/i
release_notify_jobs_done_x86_64_COTS:
image: $BUILD_BASED_IMAGE_ROCKYLINUX8
stage: notify
extends: .notify_jobs_done
variables:
ENABLE_NOTIFY_RELEASE_JOBS_DONE: 1
only:
- tags
except:
- /^.*-rc.*$/i

18
tools/notify-jobs-done.sh Normal file
View File

@@ -0,0 +1,18 @@
#!/bin/sh -x
ls -halt $CI_PROJECT_DIR/images/
TSG_OS_VERSION_FILE="$CI_PROJECT_DIR/images/tsg-os-version.txt"
TSG_OS_VERSION=
if [ -f $TSG_OS_VERSION_FILE ]; then TSG_OS_VERSION=$(cat $TSG_OS_VERSION_FILE); fi
echo $TSG_OS_VERSION
NOTIFY_CONTENT="{\"msgtype\": \"text\",\"text\": {\"content\": \"TSG-OS version: $TSG_OS_VERSION has been generated.\",\"mentioned_list\":[\"@all\"]}}"
echo $NOTIFY_CONTENT
if [ -z "$TSG_OS_VERSION" ]; then echo "TSG_OS version: $TSG_OS_VERSION is NULL."; exit 1; fi
if [ -n "$ENABLE_NOTIFY_TESTING_JOBS_DONE" ] && [ "$ENABLE_NOTIFY_TESTING_JOBS_DONE" == "1" ]; then curl "$NOTIFY_TESTING_JOBS_DONE_WEBHOOK" -H "Content-Type: application/json" -d "$NOTIFY_CONTENT"; fi
if [ -n "$ENABLE_NOTIFY_RC_JOBS_DONE" ] && [ "$ENABLE_NOTIFY_RC_JOBS_DONE" == "1" ]; then curl "$NOTIFY_RC_JOBS_DONE_WEBHOOK" -H "Content-Type: application/json" -d "$NOTIFY_CONTENT"; fi
if [ -n "$ENABLE_NOTIFY_RELEASE_JOBS_DONE" ] && [ "$ENABLE_NOTIFY_RELEASE_JOBS_DONE" == "1" ]; then curl "$NOTIFY_RELEASE_JOBS_DONE_WEBHOOK" -H "Content-Type: application/json" -d "$NOTIFY_CONTENT"; fi
rm -rf $TSG_OS_VERSION_FILE