I’m working on CICD pipeline to check json files validity.
In my .gitlab-ci.yml
I have
include:
- project: 'xxx/cicd/python-venv'
ref: '[email protected]'
file: 'python_venv.yml'
python_venv:
rules:
- when: never
check_json_venv:
extends: python_venv
stage: build
variables:
PYTHON_SETUP: 'pip install jq'
VENV_ARTIFACT_NAME: 'check_json_venv'
rules:
- when: null
check_json:
variables:
IMAGE_NAME: 'python'
IMAGE_TAG: 'latest'
IMAGE: '$IMAGE_NAME:$IMAGE_TAG'
PROJECT_PATH: '.'
image: $IMAGE
stage: test
before_script:
- source venv/bin/activate
script:
- pwd
- >
find $PROJECT_PATH -type f -name '*.json' | while read -r file; do
jq '.' "$file" > /dev/null || EXIT_CODE=$?;
if [ $EXIT_CODE != 0 ]; then
echo "EXIT_CODE: $EXIT_CODE - $file is an Invalid json"
exit 1
else
echo "EXIT_CODE: $EXIT_CODE - $file is a Valid json"
exit 0
fi
done
needs:
- job: check_json_venv
artifacts: true
When I try the script in my terminal it works
But when I push to my repo, the job fail with this error:
/usr/bin/bash: line 154: jq: command not found
I don’t understand why jq command is not found while I create a Venv and do pip install jq
as I do in local. And I have take example in a CI template which is working.
I tried to see if my script is valid ans it seems to be yes.
I have search the exit code 127 (I print in the terminal), seems to be for a command not found.
I don’t know what I can do more.
Maybe jq should be installed in global ?