I'm trying to make a script to constantly query Jira (using cron) for tickets with its custom field (containing some time information about the ticket) defined as the current time. I have the lines below in my script but it seems like JQL doesn't accept variables:
starttime=$(date +"%H:%M")
(curl \
-u username:password \
-X POST \
-H "Content-Type: application/json" \
--data '{"jql":"project = ZZZ and cf[99999] = \"$starttime\"","startAt":0,"maxResults":5,"fields":["customfield_99999","key"]}' \
"https://jira.url.com/rest/api/2/search"
) | python -m json.tool > /home/tickets.txt
The query works if the custom field value is defined but when using a variable it doesn't. Is it because of my syntax or does JQL not support this kind of query? I read the documentation and as of now I haven't found anything regarding using variables.
Thanks!
Hello,
JQL does not support using variables. You need to replace this variable with a value in your python script.
Thank you for answering! Does this mean I cannot do the action I intend to do or do you think there may be another way to implement this? I need this script to automate a task and using a variable in the query was the solution I had in mind, not until now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Something came to my mind. Maybe I can automate editing the script to always change the JQL statement. Hmmmm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you can replace the variable in your python script and send a correct JQL statement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.