Skip to content

Commit

Permalink
test: Send results to slack channel (kubeflow#466)
Browse files Browse the repository at this point in the history
Send the e2e-test results to slack channel. The
message also encloses the link to details page of the
pipeline run.
  • Loading branch information
yhwang authored Feb 11, 2021
1 parent 8170d59 commit faaabf1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .tekton/listener.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ spec:
- name: kubeflow-ns
description: kubeflow namespace
default: kubeflow
- name: slack-webhook
description: webhook URL
default: ""
- name: slack-channel
description: slack channel
default: ""
resourcetemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
Expand Down Expand Up @@ -94,6 +100,10 @@ spec:
value: $(params.kubernetes-cluster)
- name: kubeflow-ns
value: $(params.kubeflow-ns)
- name: slack-webhook
value: $(params.slack-webhook)
- name: slack-channel
value: $(params.slack-channel)
---
apiVersion: tekton.dev/v1beta1
kind: TriggerBinding
Expand Down
10 changes: 10 additions & 0 deletions .tekton/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ spec:
default: kubeflow
- name: kubernetes-cluster
description: cluster name
- name: slack-webhook
description: webhook URL
default: ""
- name: slack-channel
description: slack channel
default: ""
workspaces:
- name: pipeline-pvc
tasks:
Expand Down Expand Up @@ -246,6 +252,10 @@ spec:
value: $(params.kubernetes-cluster)
- name: kubeflow-ns
value: $(params.kubeflow-ns)
- name: slack-webhook
value: $(params.slack-webhook)
- name: slack-channel
value: $(params.slack-channel)
workspaces:
- name: task-pvc
workspace: pipeline-pvc
Expand Down
18 changes: 18 additions & 0 deletions .tekton/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ spec:
- name: archive-dir
description: archive directory
default: "."
- name: slack-webhook
description: webhook URL
default: ""
- name: slack-channel
description: slack channel
default: ""
workspaces:
- name: task-pvc
mountPath: /artifacts
Expand All @@ -240,6 +246,18 @@ spec:
value: $(params.archive-dir)
- name: KUBEFLOW_NS
value: $(params.kubeflow-ns)
- name: SLACK_WEBHOOK
value: $(params.slack-webhook)
- name: SLACK_CHANNEL
value: $(params.slack-channel)
- name: PIPELINE_URL
valueFrom:
fieldRef:
fieldPath: metadata.annotations['devops.cloud.ibm.com/pipeline-run-url']
- name: BUILD_NUMBER
valueFrom:
fieldRef:
fieldPath: metadata.annotations['devops.cloud.ibm.com/build-number']
command: ["/bin/bash", "-c"]
args:
- set -ex;
Expand Down
28 changes: 22 additions & 6 deletions scripts/deploy/iks/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ set -ex
# Need the following env
# - PIPELINE_KUBERNETES_CLUSTER_NAME: kube cluster name
# - KUBEFLOW_NS: kubeflow namespace
# - SLACK_WEBHOOK: webhook to send out the notification
# - SLACK_CHANNEL: slack channel name
# - PIPELINE_URL: url to point of the details page for this pipeline run

SLACK_WEBHOOK="${SLACK_WEBHOOK:-""}"
SLACK_CHANNEL="${SLACK_CHANNEL:-""}"
PIPELINE_URL="${PIPELINE_URL:-""}"

# These env vars should come from the build.properties that `build-image.sh` generates
echo "REGISTRY_URL=${REGISTRY_URL}"
Expand All @@ -35,6 +42,8 @@ echo "SPACE=${SPACE}"
echo "RESOURCE_GROUP=${RESOURCE_GROUP}"
echo "PIPELINE_KUBERNETES_CLUSTER_NAME=${PIPELINE_KUBERNETES_CLUSTER_NAME}"
echo "KUBEFLOW_NS=${KUBEFLOW_NS}"
echo "PIPELINE_URL=${PIPELINE_URL}"
echo "SLACK_CHANNEL=${SLACK_CHANNEL}"

# copy files to ARCHIVE_DIR for next stage if needed
echo "Checking archive dir presence"
Expand Down Expand Up @@ -138,23 +147,30 @@ run_flip_coin_example() {
RESULT=0
run_flip_coin_example 10 || RESULT=$?

PUBLISH_BUILD_STATUS=pass
STATUS_MSG=PASSED
if [[ "$RESULT" -ne 0 ]]; then
PUBLISH_BUILD_STATUS=fail
STATUS_MSG=FAILED
fi
# check if doi is integrated in this toolchain
if [ -e _toolchain.json ]; then
if jq -e '.services[] | select(.service_id=="draservicebroker")' _toolchain.json; then
PUBLISH_BUILD_STATUS=pass
if [[ "$RESULT" -ne 0 ]]; then
PUBLISH_BUILD_STATUS=fail
fi
ibmcloud doi publishbuildrecord --branch "${GIT_BRANCH}" --repositoryurl "${GIT_URL}" --commitid "${GIT_COMMIT}" \
--buildnumber "${BUILD_NUMBER}" --logicalappname "kfp-tekton" --status "$PUBLISH_BUILD_STATUS"
fi
fi

if [[ "$SLACK_CHANNEL" != "" && "$SLACK_WEBHOOK" != "" ]]; then
curl -X POST --data-urlencode "payload={\"channel\": \"#${SLACK_CHANNEL}\", \"username\": \"tekton-pipeline\", \"type\": \"mrkdwn\", \"text\": \"build: *<${PIPELINE_URL} | ${BUILD_NUMBER}>* ${STATUS_MSG}.\", \"icon_emoji\": \":robot_:\"}" \
"$SLACK_WEBHOOK"
fi

kill %1

if [[ "$RESULT" -ne 0 ]]; then
echo "e2e test FAILED"
echo "e2e test ${STATUS_MSG}"
exit 1
fi

echo "e2e test PASSED"
echo "e2e test ${STATUS_MSG}"

0 comments on commit faaabf1

Please sign in to comment.