GitLab CI遇到错误:找不到命令:AJV

时间:2020-01-24 03:57:40

标签: linux bash docker gitlab-ci npx

  • 我在GitLab CI中出错。
  • 在此之前,我创建了一个question
  • 问题已经解决,但是有一个新问题。

schema-test.sh文件内容:

#!/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错误消息:

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

感谢您的所有帮助!

1 个答案:

答案 0 :(得分:1)

假设已安装ajv (Another JSON Schema Validator),请确保没有打开编辑器询问您任何问题:根据zkat/npx issue 116,npx不会挂起,而是会说command not found: xxx

确保首先正确配置ajvcheck its version):

支持草稿-07的Ajv版本6.0.0发行了。它可能需要迁移架构或更新代码(要继续使用草稿04和v5架构,将支持草稿06架构而无需进行更改)。

请注意:要将Ajv与草稿06模式一起使用,您需要将元架构显式添加到验证程序实例中