status.py 1.59 KB
Newer Older
1
import argparse
2
import os
3

4
import requests
5

6
7
8
9
10
11
12
13
parser = argparse.ArgumentParser()
parser.add_argument(
    "--result",
    type=str,
    default="FAILURE",
)
args = parser.parse_args()

14
15
16
JOB_NAME = os.getenv("JOB_NAME")
BUILD_NUMBER = os.getenv("BUILD_NUMBER")
BUILD_ID = os.getenv("BUILD_ID")
17
COMMIT = os.getenv("GIT_COMMIT")
18

19
20
# List of status of entire job.
# https://javadoc.jenkins.io/hudson/model/Result.html
21
22
23
24
if args.result == "SUCCESS":
    status_output = "✅ CI test succeeded."
elif args.result == "NOT_BUILT":
    status_output = "⚪️ CI test cancelled due to overrun."
25
elif args.result in ["FAILURE", "ABORTED"]:
26
27
28
29
30
31
32
33
34
35
36
37
38
    status_output == "❌ CI test failed."
    JOB_LINK = os.environ["BUILD_URL"]
    response = requests.get("{}wfapi".format(JOB_LINK), verify=False).json()
    for stage in response["stages"]:
        # List of status of individual stage.
        # https://javadoc.jenkins.io/plugin/pipeline-graph-analysis/org/jenkinsci/plugins/workflow/pipelinegraphanalysis/GenericStatus.html
        if stage["status"] in ["FAILED", "ABORTED"]:
            stage_name = stage["name"]
            status_output = f"❌ CI test failed in Stage [{stage_name}]."
            break
else:
    status_output = f"[Debug Only] CI test with result [{args.result}]."

39

40
41
comment = f"""
Commit ID: {COMMIT}\n
42
Build ID: {BUILD_ID}\n
43
44
45
Status: {status_output}\n
Report path: [link](https://dgl-ci-result.s3.us-west-2.amazonaws.com/{JOB_NAME}/{BUILD_NUMBER}/{BUILD_ID}/logs/report.html)\n
Full logs path: [link](https://dgl-ci-result.s3.us-west-2.amazonaws.com/{JOB_NAME}/{BUILD_NUMBER}/{BUILD_ID}/logs/cireport.log)
46
47
"""

Rhett Ying's avatar
Rhett Ying committed
48
print(comment)