Jenkins Pipeline failed



我正在运行Jenkins管道的脚本版本。除了最后一个阶段,它贯穿了所有阶段。每次都失败。

这是Jenkins的代码,不断失败:

stage('Deploy Production') {
echo "Deploy Prod on: ${env.BRANCH_NAME}"
try {
if (env.BRANCH_NAME == 'master'){
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'XX',
usernameVariable: 'XXXXX', passwordVariable: 'XXXXXX']]) {
sh 'npm run build-prod-ci'
sh 'cf login -u ${XXXXX} -p ${XXXXXX} -a website.com -o XXX -s XXXX'
sh 'cf blue-green-deploy Dashboard'
sh 'cf delete Dashboard-old -f'
}
}
} finally {
deleteDir()
sh 'cf logout'
}
}

这是打印输出和错误消息。如果您能帮助解决这个问题,我们将不胜感激。

Plugin blue-green-deploy 1.3.0 successfully installed.
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy Development)
[Pipeline] echo
Deploy Dev on: master
[Pipeline] deleteDir
[Pipeline] sh
+ cf logout
Logging out ...
OK
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Deploy Production)
[Pipeline] echo
Deploy Prod on: master
[Pipeline] withCredentials
Masking supported pattern matches of $XXXXXX
[Pipeline] {
[Pipeline] sh
+ npm run build-prod-ci
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /v/wl/ws/Dashboard_master/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/v/wl/ws/Dashboard_master/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 
npm ERR! A complete log of this run can be found in:
npm ERR!     /v/wl/wsp/Dashboard_master/.npm/_logs/2022-07-06T22_43_57_239Z-debug.log
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] deleteDir
[Pipeline] sh
+ cf logout
Logging out ...
OK
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 254

之前使用npm命令的阶段运行良好。下面是一个有效的舞台示例:

stage('Run project tests and build') {
echo "Run project tests and build on: ${env.BRANCH_NAME}"
sh "npm run lint"
//sh "npm run compodoc-ci"
//sh "npm run test-coverage"
sh "npm run build-dev-ci"
}

这个问题是自己造成的,上面给出的评论给了我一些找到解决方案的提示。

问题是我正在移动原始Jenkins代码(我认为它被称为声明式管道)到这个形式(脚本管道?),我转换下面的代码没有思考,因为Jenkins不是我每天工作的东西…

steps {
when {
branch 'dev'
}
}
post {
always {
deleteDir()

try {
if (env.BRANCH_NAME == 'dev'){
} finally {
deleteDir()

无论如何,命令deleteDir()删除了目录,因此它再也找不到那个文件了。

谢谢大家的帮助。感谢。

教训:检查你的代码,了解它在做什么。复制粘贴只能起到一定的作用。

最新更新