Skip to content

Instantly share code, notes, and snippets.

@ricardojba
Forked from elifarley/jira-curl.sh
Created May 14, 2019 08:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardojba/972f24bce076d55b9b25d1f45e59c00f to your computer and use it in GitHub Desktop.
Save ricardojba/972f24bce076d55b9b25d1f45e59c00f to your computer and use it in GitHub Desktop.
How to use curl and here-documents to post a JSON document to create an issue in Jira in a more readable way
JIRA_REST_URL="${JIRA_REST_URL:-https://MYCOMPANY.jira.com/rest/api/2}"
JIRA_CREDENTIALS="${JIRA_CREDENTIALS:-user:password}"
# https://developer.atlassian.com/jiradev/api-reference/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-discovering-meta-data-for-creating-issues
# https://MYCOMPANY.jira.com/rest/api/2/issue/createmeta?projectKeys=MYPROJ&issuetypeNames=MyIssueType&expand=projects.issuetypes.fields
# customfield_10171: My Custom Field Name 1
# customfield_10172: My Custom Field Name 2
# This methods create a new issue of type 'MyIssueType' in project 'MYPROJ' with 2 custom fields
# and prints the key for the newly created issue
jira_new_MyIssueType() {
local jira_data="$(cat <<-EOF
{"fields":{
"summary": "This is a test summary",
"description": "Description here please",
"project": { "key": "MYPROJ" },
"issuetype": { "name": "MyIssueType"},
"customfield_10171": {"value":"My-value-1"},
"customfield_10172": [{"value":"My-value-2"}]
}}
EOF
)"
curl -D- -u "$JIRA_CREDENTIALS" -X POST --data "$jira_data" -H "Content-Type: application/json" $JIRA_REST_URL/issue/ \
| sed -re 's/^.*"key":"([^"]+)".*/\1/'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment