我目前正在配置我们的jenkins工作,并在为我们的一个JavaScript项目设置多管道项目时遇到问题。
这个javascript项目使用Jest测试运行npm test:
"test": "jest --verbose"
当jenkins执行作业时,它失败并出现非描述性错误。只是说失败。如果我改变jenkins文件直接调用' jest'而不是' npm test',它以ENOENT in event.js - line 160
失败,但没有提供关于哪些文件丢失或无法访问的更多信息。
如果我在运行jenkins的机器上手动运行测试,它可以使用nodejs的系统安装,以及nodejs jenkins插件。
它也适用于常规项目:如果我只是设置一个链接到我们的repo的常规项目,它可以正常运行测试,因此它专门链接到管道设置。也许与沙箱groovy有关的事情呢?
我的jenkinsfile是:
node('master') { // <1>
echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"
checkout scm
stage('Test') {
env.NODE_ENV = "test"
def nodejs = tool name: 'Recent Node', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
env.PATH = "${nodejs}/bin:${env.PATH}"
sh 'node -v'
sh 'npm prune'
sh 'npm install'
//sh 'npm install -g jest'
sh 'npm test --verbose'
}
...
}
更多信息,Jenkins的确切输出:
[Westeros_Shae_master-LLONGEYFZHPPZGPNCY5NX2JCP6ERHRXGIYARHJWEF662AIZ4TGDQ] Running shell script
+ npm test --verbose npm info it worked if it ends with ok npm verb cli [ '/Users/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/bin/node', npm verb cli '/Users/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/bin/npm', npm verb cli 'test', npm verb cli '--verbose' ] npm info using npm@4.0.5 npm info using node@v7.4.0 npm verb run-script [ 'pretest', 'test', 'posttest' ] npm info lifecycle shae@1.0.0~pretest: shae@1.0.0 npm info lifecycle shae@1.0.0~test: shae@1.0.0 shae@1.0.0 test /Users/jenkins/.jenkins/workspace/Westeros_Shae_master-LLONGEYFZHPPZGPNCY5NX2JCP6ERHRXGIYARHJWEF662AIZ4TGDQ jest --verbose
npm verb lifecycle shae@1.0.0~test: unsafe-perm in lifecycle true npm verb lifecycle shae@1.0.0~test: PATH: /Users/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/lib/node_modules/npm/bin/node-gyp-bin:/Users/jenkins/.jenkins/workspace/Westeros_Shae_master-LLONGEYFZHPPZGPNCY5NX2JCP6ERHRXGIYARHJWEF662AIZ4TGDQ/node_modules/.bin:/Users/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/nodejs/bin:/usr/local/bin:$PATH npm verb lifecycle shae@1.0.0~test: CWD: /Users/jenkins/.jenkins/workspace/Westeros_Shae_master-LLONGEYFZHPPZGPNCY5NX2JCP6ERHRXGIYARHJWEF662AIZ4TGDQ npm info lifecycle shae@1.0.0~test: Failed to exec test script