0
  • I got an error in GitLab CI.
  • Before that, I created a question.
  • The problem was solved, but there was a new problem.

schema-test.sh file contents:

#!/usr/bin/env bash

# Test all file ends with schema.json via ajv

CURRENT_DIR=`dirname "$0"`

cd $CURRENT_DIR

for SCHEMA_FILE in *.schema.json
do
    SAMPLE_FILE=samples/${SCHEMA_FILE/schema/sample}
    echo Schema file: $SCHEMA_FILE
    if [ -f $SAMPLE_FILE ]
    then
        echo Found sample file: $SAMPLE_FILE
        npx ajv -s $SCHEMA_FILE -d $SAMPLE_FILE
    else
        echo "*NO* sample file found for $SCHEMA_FILE"
    fi
done

Gitlab CI error message:

23 $ yarn test:schema
24 yarn run v1.21.1
25 $ ./src/schemas/schema-test.sh
26 Schema file: dev-assistant.schema.json
27 Found sample file: samples/dev-assistant.sample.json
28 npx: installed 6 in 1.124s
29 command not found: ajv
30 Schema file: form.schema.json
31 *NO* sample file found for form.schema.json
32 Schema file: news.schema.json
33 *NO* sample file found for news.schema.json
34 Schema file: repos.schema.json
35 Found sample file: samples/repos.sample.json
36 npx: installed 6 in 0.911s
37 command not found: ajv
38 Schema file: team-members.schema.json
39 Found sample file: samples/team-members.sample.json
40 npx: installed 6 in 0.902s
41 command not found: ajv
42 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
43 error Command failed with exit code 1.
47 ERROR: Job failed: command terminated with exit code 1

Thank you for all of your help!

liby
  • 679
  • 6
  • 13

1 Answers1

1

Assuming ajv (Another JSON Schema Validator) is installed, make sure it does not to open an editor to ask you anything: according to zkat/npx issue 116, instead of hanging, npx would say command not found: xxx.

Make sure ajv is properly configured first (check its version):

Ajv version 6.0.0 that supports draft-07 is released. It may require either migrating your schemas or updating your code (to continue using draft-04 and v5 schemas, draft-06 schemas will be supported without changes).

Please note: To use Ajv with draft-06 schemas you need to explicitly add the meta-schema to the validator instance

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm sorry, I don't understand the connection between your answer and my question. Could you clarify it a bit? Thank you. – liby Jan 24 '20 at 17:07
  • @liby The error message you see `command not found: ...` is sometimes triggered when the `npx xxx` command want to open an editor and might froze as a result. Instead of being frozen, it prints that error message. – VonC Jan 24 '20 at 22:15