-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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