princenyeche/Automating-Jira-Shell

When I run the query it is throwing syntax error

Closed this issue · 11 comments

export.sh: line 18: ((: c=: syntax error: operand expected (error token is "=")

@vikarri which of the shell script from the repo are you trying to use?

@princenyeche It is exportJiraIssues.sh

@vikarri There's nothing wrong with the script. I tested it again and it work on unix like environment. If you're on windows, what application are you using to run bash?

@princenyeche I'm on mac. I'm running it against the JIRA server. This is my script

email=vinod.karri@XXX.com
apitoken=XXXXXXXXXXXXXXXXXX

Enter Instance name without full URLs

read -p "jira.xxxxx.com" instance

The Amount of issues you want exported per CSV file e.g: 100

read -p "100" issue_1

Where you want the Loop counter to stop counting e.g. 400

read -p "400" issue_2

The Max range where you want the loop to jump to the issues rather to start the next export, it could be the same as the Initial number or lower. e.g.100

read -p "400" issue_3

The JQL URLs

format: project%20%3D%20AT2%20ORDER%20BY%20Rank%20ASC

you can copy this URL from the Issue navigator search by searching some issues and copy the URL

read -p "https://jira.xxxxx.com/browse/WHENGIHE-5576?jql=project%20%3D%20WH-ENGMNT-IHE%20AND%20issuetype%20!%3D%20Sub-Task%20ORDER%20BY%20priority%20DESC%2C%20updated%20DESC" jql_url

run a loop to cycle through the search, limit is 1K issues per CSV file by default.

for (( c=$issue_1; c<=$issue_2; c=c+$issue_3 ))
do
echo "https://$instance/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=$jql_url&tempMax=1000&pager/start=${c}"
curl -o "$c.csv" -u "$email":"$apitoken" -X GET -H "Content-Type: application/json" "https://$instance/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=$jql_url&tempMax=1000&pager/start=${c}"
done
echo "


    Export Complete

I believe it should work on a server instance as well but your jql is wrong. The script expects a valid JQL query not a full url to a JQL. Example below based on your own url

project%20%3D%20WH-ENGMNT-IHE%20AND%20issuetype%20!%3D%20Sub-Task%20ORDER%20BY%20priority%20DESC%2C%20updated%20DESC"

The reason for the encoded url is to avoid space characters, so the curl script can work.

Hey @vikarri were you able to perform what you need?

@princenyeche I have updated my jql and I still receive the error

exportJiraIssues.sh: line 18: ((: c=: syntax error: operand expected (error token is "=")

@princenyeche I tried on cloud. I see the same error message

#!/bin/bash
# User CREDENTIALS
email=vinod.reddy@abc.com
apitoken=LsC
# Enter Instance name without full URLs
read -p "jira.abc.com" instance
# The Amount of issues you want exported per CSV file e.g: 100
read -p "1" issue_1
# Where you want the Loop counter to stop counting  e.g. 400
read -p "200" issue_2
# The Max range where you want the loop to jump to the issues rather to start the next export, it could be the same as the Initial number or lower. e.g.100
read -p "200" issue_3
# The JQL URLs
# format: project%20%3D%20AT2%20ORDER%20BY%20Rank%20ASC
# you can copy this URL from the Issue navigator search by searching some issues and copy the URL
read -p "project%20%3D%20WH-ENGMNT-IHE%20AND%20issuetype%20!%3D%20Sub-Task%20ORDER%20BY%20priority%20DESC%2C%20updated%20DESC" jql_url
# run a loop to cycle through the search, limit is 1K issues per CSV file by default.
for (( c=$issue_1; c<=$issue_2; c=c+$issue_3 ))
do
	echo "https://$instance/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=$jql_url&tempMax=1000&pager/start=${c}"
  curl -o "$c.csv" -u "$email":"$apitoken" -X GET -H "Content-Type: application/json" "https://$instance/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=$jql_url&tempMax=1000&pager/start=${c}"
done
echo "
*********************************************
        Export Complete
*********************************************
"

When you're entering the first digit, are you typing a space character on your terminal?

How about you modify the code like below and see if the same error persist?

#!/bin/bash
# User CREDENTIALS
email=email@address.com
apitoken=3yXXXXXXXXXXXXXX
# Enter Instance name without full URLs
read -p "Enter Instance Name (only): " instance
# The Amount of issues you want exported per CSV file e.g: 100
read -p "Enter Issue export in digits: " issue_1
# Where you want the Loop counter to stop counting  e.g. 400
read -p "Enter Loop Number in digits: " issue_2
# The Max range where you want the loop to jump to the issues rather to start the next export, it could be the same as the Initial number or lower. e.g.100
read -p "Enter Issue export Stop Cycle in digits: " issue_3
# The JQL URLs
# format: project%20%3D%20AT2%20ORDER%20BY%20Rank%20ASC
# you can copy this URL from the Issue navigator search by searching some issues and copy the URL
read -p "Enter JQL URL: " jql_url
# run a loop to cycle through the search, limit is 1K issues per CSV file by default.
for (( c=100; c<=400; c=c+100 ))
do
	echo "https://$instance.atlassian.net/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=$jql_url&tempMax=1000&pager/start=${c}"
  curl -o "$c.csv" -u "$email":"$apitoken" -X GET -H "Content-Type: application/json" "https://$instance.atlassian.net/sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv?jqlQuery=$jql_url&tempMax=1000&pager/start=${c}"
done
echo "
*********************************************
        Export Complete
*********************************************
"

@vikarri let me know if you're able to resolve this issue with my above suggestion.