-
Notifications
You must be signed in to change notification settings - Fork 0
/
xray-ap-upload-cucumber-report.sh
77 lines (73 loc) · 2.81 KB
/
xray-ap-upload-cucumber-report.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
CUCUMBER_JSON_REPORT_PATH=./reports/cucumber.json
TEST_PLAN_KEY="$1"
IS_FEATURE="$2"
# Input variables validation
if [ "$TEST_PLAN_KEY" == "" ]; then
echo "TEST_PLAN_KEY missing. Usage: /xray-api-upload-cucumber-report.sh <TEST_PLAN_KEY>"
exit 1
fi
if [ "$XRAY_CLIENT_ID" == "" ]; then
echo "XRAY_CLIENT_ID env var is empty" exit 1
fi
if [ "$XRAY_CLIENT_SECRET" == "" ]; then
echo "XRAY_CLIENT_SECRET env var is empty"
exit 1
fi
if [ ! -f $CUCUMBER_JSON_REPORT_PATH ]; then echo "No cucumber JSON report found at $CUCUMBER_JSON_REPORT_PATH"
exit 1
fi
#Precalculations
token=$(curl -H "Content-Type: application/json" -X POST --data "{ \"client_id\": \"$XRAY_CLIENT_ID\",\"client_secret\": \"$XRAY_CLIENT_SECRET\" }" https://xray.cloud.getxray.app/api/v2/authenticate| tr -d '"')
today=`date "+%Y-%m-%d"`
transition=11
executionStatusTransitionComment="Execution moved to PASSED"
if [ "$ARE_TESTS_FAILED" == "Y" ]; then
transition=21
executionStatusTransitionComment="Execution moved to FAILED because of failed tests"
fi
#Info file for creating the new ticket
if [ "$IS_FEATURE" == "N" ]; then
echo '{
"fields": {
"project": {
"id": "10002"
},
"summary": "'$TEST_PLAN_KEY' '$today' Test Execution Results",
"description": "'$TEST_PLAN_KEY' '$today' Test Execution Results from Gitlab Pipeline. \n'$executionStatusTransitionComment'",
"issuetype": {
"id": "10008"
}
},
"xrayFields": {
"testPlanKey": "'$TEST_PLAN_KEY'"
}
}' > /tmp/issueFields.json
else
echo '{
"fields": {
"project": {
"id": "10002"
},
"parent": {
"key": "'$TEST_PLAN_KEY'"
},
"summary": "'$TEST_PLAN_KEY' '$today' Test Execution Results",
"description": "'$TEST_PLAN_KEY' '$today' Test Execution Results from Gitlab Pipeline. \n'$executionStatusTransitionComment'",
"issuetype": {
"id": "10010"
}
}
}' > /tmp/issueFields.json
fi
echo "Ticket $TEST_PLAN_KEY for IS_FEATURE $IS_FEATURE with $executionStatusTransitionComment"
cat /tmp/issueFields.json
curl -H "Content-Type: multipart/form-data" -X POST -F "info=@/tmp/issueFields.json" -F "results=@${CUCUMBER_JSON_REPORT_PATH}" -H "Authorization: Bearer ${token}" https://xray.cloud.getxray.app/api/v2/import/execution/cucumber/multipart > output.text
cat output.text
#Status change using Jira transition endpoint
executionUrlV2=`cat output.text | cut -d '"' -f 12`
transitionUrl=`echo $executionUrlV2/transitions`
echo
echo '{"transition": {"id": '$transition'}}' > transition.json
cat transition.json
curl -X POST "$transitionUrl" --user [email protected]:$JIRA_API_TOKEN -H 'Accept: application/json' -H 'Content-Type: application/json' --data @transition.json > transition.text
cat transition.text