i want to pass my variable in to the JSON object of JIRA API

Kmjira August 26, 2020

i want to pass my variable in to the JSON object of JIRA API . Here i want to pass this variable summary into the fields .

var summary = " Create ticket"

 "fields": { "summary": "Summary" ,"issuetype": { "id": "1" }, assignee": { "name": "abc" },                        "project": {"id": "23601"}  }

Kindly share the format to pass the variable into this JSON .

Thanks in Advance .

2 answers

0 votes
Deepak Gupta December 2, 2021

I came across this thread while looking for solution to my problem. I am not sure if kmjira was also facing the same problem. 

 

I wanted to define a variable and then use it in the jql search query while running this code via Jenkins build step. I was able to do this the following way. I have used two variables OlderThan and jira_sql. The JSON output will be recorded in file OpenTickets.txt

 

OlderThan=30

jira_jql="Project = PROJECTNAME AND status not in (closed, resolved, done) AND created < -${OlderThan}d ORDER BY created ASC"


if [[ ! -z "${jira_jql}" ]]
then
curl --location --request POST "https://jira.xyz.com/rest/api/2/search?pretty=true" \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ZXRhbzpFdGFvQDEyMw==' \
--data '{
"jql": "'"${jira_jql}"'",
"startAt":0,
"maxResults":1000,
"fields":["key","issuetype","summary","priority","status","created","updated","assignee"]
}' > /tmp/OpenTickets.txt

PS: Posted my solution here so that may be it can help someone else like me.

0 votes
Ibrahim Ghalghay June 21, 2021

I find it strange to see this important question not answered even after 10 months!!! I found similar questions in the community, also not answered!!!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events