Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPPE addition / modification of CircleCI orb jira #609

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 1 addition & 58 deletions jira/orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,64 +247,7 @@ commands:
} >> $BASH_ENV
name: Setting variables
- run:
command: |
#!/bin/bash
query_issue() {
if [ -z "$PARAM_API_TOKEN" ]; then
echo "Mandatory parameters have not been set! You must specify a JIRA API token in order to allow JIRA to create an issue with appropriate details on this board."
echo "You must create a JIRA API token (ideally for a service user) in JIRA using the following instructions: https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/"
exit 1
fi

if [ -z "$PARAM_PROJECT_KEY" ]; then
echo "Mandatory parameter PROJECT_KEY has not been set! e.g.PARAM_PROJECT_KEY=\"CPPE\"."
exit 1
fi

if [ -z "$PARAM_USER_EMAIL_ID" ]; then
echo "Mandatory parameters have not been set! You must specify a JIRA user email id in order to allow JIRA to create an issue with appropriate details on this board. [email protected]"
exit 1
fi

if [ -z "$PARAM_JQL_QUERY" ]; then
echo "Mandatory parameter PARAM_JQL_QUERY has not been set! e.g.PARAM_JQL_QUERY=\"Blocker\"."
exit 1
fi

JIRA_AUTH_HTTP_STATUS=$(curl --write-out "%{http_code}" -s "https://ovotech.atlassian.net/rest/api/3/project/${PARAM_PROJECT_KEY}" --user "$PARAM_USER_EMAIL_ID:$PARAM_API_TOKEN" --header 'Accept: application/json' --output /dev/null)

# Checking if returned status code is not 200
if [ "${JIRA_AUTH_HTTP_STATUS}" != "200" ]; then
echo "${JIRA_AUTH_HTTP_STATUS}: Unable to authenticate because provided JIRA Token is invalid! Exiting..."
echo "You must create a JIRA API token (ideally for a service user) in CircleCI using the following instructions: https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/"
exit 1
fi

JSON_BODY=$(jq -rcn --arg jql_query "$PARAM_JQL_QUERY" '
{
"fields": [
"summary"
],
"fieldsByKeys": false,
"jql": "\($jql_query)"
}
')

EXISTING_ISSUES=$(curl --request POST --url 'https://ovotech.atlassian.net/rest/api/3/search' --user "$PARAM_USER_EMAIL_ID:$PARAM_API_TOKEN" --header 'Accept: application/json' --header 'Content-Type: application/json' --data "$JSON_BODY")
EXISTING_ISSUES_COUNT=$(echo "${EXISTING_ISSUES}" | jq '.issues | length')
if [ "${EXISTING_ISSUES_COUNT}" != 0 ]; then
echo "An existing issue was found for the query '$PARAM_JQL_QUERY'!"
exit 1
else
echo "No issue was found for the query '$PARAM_JQL_QUERY'."
fi
}

# Will not run if sourced for bats-core tests.
ORB_TEST_ENV="bats-core"
if [ "${0#*"$ORB_TEST_ENV"}" == "$0" ]; then
query_issue
fi
command: "#!/bin/bash\nquery_issue() {\n if [ -z \"$PARAM_API_TOKEN\" ]; then\n echo \"Mandatory parameters have not been set! You must specify a JIRA API token in order to allow JIRA to create an issue with appropriate details on this board.\"\n echo \"You must create a JIRA API token (ideally for a service user) in JIRA using the following instructions: https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/\"\n exit 1\n fi\n\n if [ -z \"$PARAM_PROJECT_KEY\" ]; then\n echo \"Mandatory parameter PROJECT_KEY has not been set! e.g.PARAM_PROJECT_KEY=\\\"CPPE\\\".\"\n exit 1\n fi\n\n if [ -z \"$PARAM_USER_EMAIL_ID\" ]; then\n echo \"Mandatory parameters have not been set! You must specify a JIRA user email id in order to allow JIRA to create an issue with appropriate details on this board. [email protected]\"\n exit 1\n fi\n\n if [ -z \"$PARAM_JQL_QUERY\" ]; then\n echo \"Mandatory parameter PARAM_JQL_QUERY has not been set! e.g.PARAM_JQL_QUERY=\\\"Blocker\\\".\"\n exit 1\n fi\n\n JIRA_AUTH_HTTP_STATUS=$(curl --write-out \"%{http_code}\" -s \"https://ovotech.atlassian.net/rest/api/3/project/${PARAM_PROJECT_KEY}\" --user \"$PARAM_USER_EMAIL_ID:$PARAM_API_TOKEN\" --header 'Accept: application/json' --output /dev/null)\n\n # Checking if returned status code is not 200\n if [ \"${JIRA_AUTH_HTTP_STATUS}\" != \"200\" ]; then\n echo \"${JIRA_AUTH_HTTP_STATUS}: Unable to authenticate because provided JIRA Token is invalid! Exiting...\"\n echo \"You must create a JIRA API token (ideally for a service user) in CircleCI using the following instructions: https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/\"\n exit 1\n fi\n\n JSON_BODY=$(jq -rcn --arg jql_query \"$PARAM_JQL_QUERY\" '\n {\n \"fields\": [\n \"summary\"\n ],\n \"fieldsByKeys\": false,\n \"jql\": \"\\($jql_query)\"\n }\n')\n\n EXISTING_ISSUES=$(curl --request POST --url 'https://ovotech.atlassian.net/rest/api/3/search' --user \"$PARAM_USER_EMAIL_ID:$PARAM_API_TOKEN\" --header 'Accept: application/json' --header 'Content-Type: application/json' --data \"$JSON_BODY\")\n EXISTING_ISSUES_COUNT=$(echo \"${EXISTING_ISSUES}\" | jq '.issues | length')\n if [ \"${EXISTING_ISSUES_COUNT}\" != 0 ]; then\n echo \"An existing issue was found for the query '$PARAM_JQL_QUERY'!\"\n exit 1\n else\n echo \"No issue was found for the query '$PARAM_JQL_QUERY'.\"\n fi\n\n \n}\n\n# Will not run if sourced for bats-core tests.\nORB_TEST_ENV=\"bats-core\"\nif [ \"${0#*\"$ORB_TEST_ENV\"}\" == \"$0\" ]; then\n query_issue\nfi\n"
name: Query JIRA board
jobs:
create_issue:
Expand Down