-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep.sh
59 lines (50 loc) · 1.56 KB
/
step.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
#!/bin/bash
# Function to check if a variable is empty
check_empty() {
if [[ -z "$1" ]]; then
echo "Error: $2 is required but not provided."
exit 1
fi
}
# Check mandatory inputs
check_empty "$jira_username" "Jira Username"
check_empty "$jira_token" "Jira API Token"
check_empty "$jira_url" "Jira URL"
check_empty "$jira_release_id" "Jira Release ID"
check_empty "$release_status" "Mark Release as Completed"
echo "Updating release..."
# Construct JSON payload
JSON_PAYLOAD=$(cat <<EOF
{
"id": "$jira_release_id",
"released": "$release_status"
EOF
)
# Include releaseDate field if it's not empty
if [[ -n "$release_date" ]]; then
JSON_PAYLOAD+=$',\n "releaseDate": "'"$release_date"'"'
fi
JSON_PAYLOAD+=$'\n}'
# Send the request
RESPONSE=$(curl -s -X PUT -u "$jira_username:$jira_token" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD" \
"$jira_url/rest/api/3/version/$jira_release_id")
# Define color codes for terminal output
red=$'\e[31m'
green=$'\e[32m'
reset=$'\e[0m'
echo $RESPONSE
# Check if the Jira release update was successful or failed
if [[ $RESPONSE == *"errorMessages"* ]]; then
echo "${red}❗️ Failed $RESPONSE ${reset}"
envman add --key JIRA_RELEASE_UPDATE_SUCCESS --value false
exit -1
else
# If the update was successful, mark it as successful
name="$(echo $RESPONSE | jq '.name' | tr -d '"')"
variable=$( [ "$release_status" = true ] && echo "release" || echo "draft" )
echo "${green}✅ Success!${reset} $name release has been updated to $variable"
envman add --key JIRA_RELEASE_UPDATE_SUCCESS --value true
exit 0
fi