#!/bin/bash # Load environment variables from .env file source .env # Jira API URL to get issues assigned to the user in the current sprint with "READY FOR DEV" status JQL_QUERY="assignee=$ASSIGNEE_ID%20AND%20sprint%20in%20openSprints()%20AND%20project%20%3D%20%22$PROJECT_KEY%22" URL="https://$JIRA_DOMAIN/rest/agile/1.0/board/$BOARD_ID/issue?jql=$JQL_QUERY&maxResults=100" # Make the API request with curl response=$(curl -s -X GET "$URL" -H "Authorization: Basic $(echo -n "$EMAIL:$API_TOKEN" | base64)" -H "Accept: application/json") # Check if there are issues and filter by status "READY FOR DEV" issues_count=$(echo "$response" | jq '.issues | length') if [ -z "$issues_count" ]; then issues_count=0 fi if [ "$issues_count" -gt 0 ]; then echo "Issues Assigned to User in Current Sprint with Status 'READY FOR DEV' on Board $BOARD_ID:" echo "$response" | jq -r '.issues[] | select(.fields.status.name == "READY FOR DEV") | "\(.key) - \(.fields.summary) [Status: \(.fields.status.name)]"' else echo "No issues found assigned to the user in the current sprint with status 'READY FOR DEV'." fi
below works in powershell,looking for similar in bash
------------------------------------------------------
$JiraDomain = "domain.atlassian.net" $Email = "user@domain.com" $ApiToken = "xxxxxxxxxxxxxxxxxxx" # The requestor token (API token) $BoardId = 100 # Board ID $AssigneeId = "6171xxxxxxxxxxxxxxx" # Assignee (user) ID #$Status = "IN DEV" # Status filter $Status = "READY FOR DEV" # Status filter $Project = "PROJECTNAME" # Encode credentials in Base64 $EncodedAuth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($Email):$($ApiToken)")) # Step 1: Get the list of open sprints for the board (to get current sprint ID) $sprintsUrl = "https://$JiraDomain/rest/agile/1.0/board/$BoardId/sprint" $sprintsResponse = Invoke-RestMethod -Uri $sprintsUrl -Method Get -Headers @{ "Authorization" = "Basic $EncodedAuth" "Accept" = "application/json" } # Assuming the active/current sprint has a state of "ACTIVE" $currentSprintId = $sprintsResponse.values | Where-Object { $_.state -eq "ACTIVE" } | Select-Object -First 1 -ExpandProperty id # Step 2: Get the issues assigned to the user in "READY FOR DEV" status, and in the current sprint $JqlQuery = "assignee=$AssigneeId%20AND%20status=%22$Status%22%20AND%20sprint%20in%20openSprints()%20AND%20project%20=%20%22$Project%22" $issuesUrl = "https://$JiraDomain/rest/agile/1.0/board/$BoardId/issue?jql=$JqlQuery&maxResults=10" $issuesResponse = Invoke-RestMethod -Uri $issuesUrl -Method Get -Headers @{ "Authorization" = "Basic $EncodedAuth" "Accept" = "application/json" } # Step 3: Loop through the issues and filter based on the current sprint if ($issuesResponse.issues.Count -gt 0) { Write-Host "Issues Assigned to User with Status 'READY FOR DEV' in Current Sprint:" foreach ($issue in $issuesResponse.issues) { # Check if the issue's sprint is the current sprint # $issueSprints = $issue.fields.sprint # if ($issueSprints -and $issueSprints.id -eq $currentSprintId) { Write-Host "$($issue.key) - $($issue.fields.summary) [Status: $($issue.fields.status.name)]" #} } } else { Write-Host "No issues found assigned to the user with 'READY FOR DEV' status in the current sprint." }
Hi,
I think there are some points to check, since you mentioned that in powershell it works. I would start by trying to use "--data-urlencode" to correctly encode JQL:
# Make the API request with curl
response=$(curl -s -X GET "$URL" \
-H "Authorization: Basic $(echo -n "$EMAIL:$API_TOKEN" | base64)" \
-H "Accept: application/json" \
--data-urlencode "jql=$JQL_QUERY" \
--data-urlencode "maxResults=100")
The & in the URL can be interpreted as a special character by the shell. --data-urlencode ensures that special characters such as = and spaces are correctly encoded.
I also noticed that your endpoint uses:
URL="https://$JIRA_DOMAIN/rest/agile/1.0/board/$BOARD_ID/issue?jql=$JQL_QUERY&maxResults=100"
In this case, it might be better to filter by:
URL="https://$JIRA_DOMAIN/rest/api/2/search?jql=$JQL_QUERY&maxResults=100"
If the JSON returned by Jira has no issues, JQ may fail. Check with:
echo "Response: $response"
If there is an error, it may be that JQ is unable to process the response.
If you are receiving any type of error, it would be interesting to share so we can go into more detail.
P.S: Remembering that these are some of the things I would do in my script to try to get the result, I hope it helps you in some way, or else it brings an error so we can analyze it better
Best Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Layssa Souza thx for those updates ,I tried using those updates but no results,no errors ,
if you could provide a working similar bash script using curl to list current tickets with a status filter in current open sprint for auth using email,apitoken
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
similar script in powershell works ,shows current tickets
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.