Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jq: command not found in GitLab CI file

In .gitlab-ci.yml

stages:
  - test-jq

    test-jq:
      stage: test-jq
      image: ruby:2.5
      script:
        - apt-get update
        - apt-get install -y git jq
        - git config --global user.email "$GITLAB_USER_EMAIL"
        - git config --global user.name "$GITLAB_USER_NAME"
        - LAST_COMMIT_SHA=$(
          curl -s \
           --header "PRIVATE-TOKEN:$CLONE_KEY" \
           "$CI_API_V4_URL/projects/$CI_PROJECT_ID/repository/commits/$CI_COMMIT_SHA" |\
           jq -r '.parent_ids | del(.[] | select(. == "'$CI_COMMIT_BEFORE_SHA'")) | .[-1]'

      )

throwing an error: /bin/bash: line 158: jq: command not found

like image 789
gcpdev Avatar asked Feb 11 '26 02:02

gcpdev


1 Answers

Another approach is to set all the installation part before your scripts, as shown here, using before_script:

image: node:latest

before_script:
  - apt-get -qq update
  - apt-get install -y jq

That way, you can make sure the environment is correctly set up once your script starts.

like image 101
VonC Avatar answered Feb 15 '26 11:02

VonC