Issue with CircleCI Script: Permission Denied, Token Decoding Error, and Exit Code 1

81 Views Asked by At

I'm encountering a set of errors in my CircleCI script that involves fetching data from Jira and performing some actions based on the retrieved information. The script aims to perform various tasks, including API requests, token handling, and conditional logic.

E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
LICENSE
cx
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 17285 0 17285 0 0 38868 0 --:--:-- --:--:-- --:--:-- 38842
Creating directory
Token decoding error: token contains an invalid number of segments
Fail with code 1

Exited with code exit status 1
CircleCI received exit code 1

Here's a portion of the relevant script for context:

- run:
 name: cxone - Capture FIX_VERSION
 command: |
 if [ -f "$HOME/jira_id.txt" ]; then
   JIRA_ID=$(cat $HOME/jira_id.txt)
   apt update && apt install -y curl jq
   VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate - 
   Dexpression=project.version -q -DforceStdout)
   ARTIFACT_ID=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate - 
   Dexpression=project.artifactId -q -DforceStdout)
   curl -sLJO https://github.com/Checkmarx/ast-cli/releases/download/2.0.52/ast- 
   cli_linux_x64.tar.gz
   tar -xzvf ast-cli_linux_x64.tar.gz
   rm -rf ast-cli_linux_x64.tar.gz
   JIRA_FIX_VERSION=$(curl -u [email protected]:$DEV_JIRA_TOKEN -X GET 
   https://xxx.yyy.net/rest/api/latest/issue/$JIRA_ID | jq -r '.fields.fixVersions[].name')
   FIX_VERSION=$(echo "$JIRA_FIX_VERSION" | sort -V | head -n 1)
   if [[ "$FIX_VERSION" == "null" || "$FIX_VERSION" == "[]" ]]; then
     echo "No fix version tagged in Jira ticket thus using the default value"
     export FIX_VERSION="abc"
   fi
bash -c "./cx scan create -s ~/repo --project-name $ARTIFACT_ID --project-tags $FIX_VERSION --branch $CIRCLE_BRANCH --apikey {api_key}; E_CODE=\$?; if [[ \$E_CODE -eq 0 ]] || [[ \$E_CODE -eq 156 ]]; then echo Success with code \$E_CODE; exit 0; else echo Fail with code \$E_CODE; exit 1; fi"

Any insights or suggestions on how to address these issues would be greatly appreciated.

Thank you in advance for your assistance!

1

There are 1 best solutions below

0
Ayesha Khan On

I successfully addressed this issue by incorporating the "sudo" command before executing the "apt" commands. Additionally, I resolved the situation by regenerating the API key