Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Passing a Variable in json Object

I need to create a Jira ticket using rest API. Is there a way to pass in a date variable to a custom due date field?


 "customfield_10111": { "value": "{{ cr_due_date }}" }, doesn't seem to work.


- name: Ansible date fact example

command: "date +'%m-%d-%Y' -d '+3 days'"

register: result

- set_fact:

cr_due_date: "{{ result.stdout }}"


- name: create pre-approved CR uri: url: "{{ jira_cr_request_api_url }}" method: POST headers: Content-Type: "application/json" body: "{{ lookup('file','test_jira.json') }}" body_format: json user: "{{ jira_username }}" password: "{{ jira_password }}" validate_certs: no return_content: yes force_basic_auth: yes status_code: 201 follow_redirects: false register: jira_issue

{ "fields": { "project": { "key": "CR" }, "summary": "testing jira ticket automation", "description": "Creating of an issue using project keys and issue type names using the REST API", "issuetype": { "id": "10301" }, "customfield_13300": [{"value" : "AWS"}], "customfield_10111": { "value": "{{ cr_due_date }}" }, "customfield_13303": { "value": "Ops" }, "customfield_13901": {"value": "OPS" , "child": {"id": "13308"}} }}

2 answers

0 votes

Not sure if my situation below can help you, but I think its worth a try.


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

You may want to take some hints from here and adapt to your situation.


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

if [[ ! -z "${jira_jql}" ]]
curl --location --request POST "" \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ZXRhbzpFdGFvQDEyMw==' \
--data '{
"jql": "'"${jira_jql}"'",
}' > /tmp/OpenTickets.txt

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

Hi , Did you get the answer for this Question , If yes then kindly share the format .


Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you