我有一个Jenkinsfile,其中的构建和测试在同一Slave上运行。 我的要求是,构建必须在一个从属服务器上(例如A),测试必须在另一个从属服务器上(例如B)运行。
我只是设置了从站B,并且可以在Jenkins-> Manage节点中看到我的从站A和B。 问题是构建阶段可以成功运行,但是我的prepare_test和test阶段未在从属B上执行。
下面是出现的问题:
1。)构建阶段成功后,出现以下错误:
“ java.lang.NoSuchMethodError:在步骤[归档,bat,构建,catchError,签出,deleteDir,dir,dockerFingerprintFrom,dockerFingerprintRun,dockerNode,echo,emailext,emailextrecipients,envVarsForTool,错误中找不到此类DSL方法'代理' ,fileExists,findBuildScans,getContext,git,input,isUnix,junit,库,libraryResource,加载,锁定,邮件,里程碑,节点,并行,powershell,属性,publishHTML,pwd,readFile,readTrusted,resolveScm,重试,脚本,sh ,睡眠,阶段,存储,步骤,svn,超时,时间戳,tm,工具,未归档,不稳定,取消存储,validateDeclarativePipeline,waitUntil,warnError,withContext,withCredentials,withDockerContainer,withDockerRegistry,withDockerServer,withEnv,wrap,writeFile,ws]或符号[all,allOf,always,ant,antFromApache,antOutcome,antTarget,any,anyOf,apiToken,体系结构,archiveArtifacts,artifactManager,attach,authorizationMatrix,batchFile,booleanParam,分支,brokenBuildSuspects,brokenTestsSuspects, buildButton,buildDiscarder,buildTimestamp,buildTimestamp java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java 在java.lang.Thread.run(Thread.java:748) 完成:失败 “
2。)在我可以看到与构建相关的阶段的同时,看不到分支的“ prepare_test”和“ test”阶段。
附上我的jenkinsfile代码:
pipeline {
agent none
options {
skipDefaultCheckout true
}
stages {
stage('build') {
agent {
docker {
image 'XYZ'
args '-v /etc/localtime:/etc/localtime:ro'
}
}
options { skipDefaultCheckout(true) }
steps {
echo '########################################## Building #########################################'
// trigger the build
sh 'scm-src/build.sh all-projects'
}
}
}
}
pipeline {
agent {
label 'laptop-hp'
}
stages {
stage('prepare_test') {
agent {
docker {
image 'ABC'
args '-v /home/jenkins/.ssh/:/home/jenkins/.ssh:ro -v /etc/localtime:/etc/localtime:ro'
}
}
options { skipDefaultCheckout(true) }
steps {
echo '####################################### Prepare Test Environment ############################'
sh 'scm-src/test.sh prepare'
}
}
stage('test') {
agent {
docker {
image 'ABC'
args '-v /home/jenkins/.ssh/:/home/jenkins/.ssh:ro -v /etc/localtime:/etc/localtime:ro'
}
}
options { skipDefaultCheckout(true) }
steps {
echo '########################################## Testing ##########################################'
sh 'scm-src/test.sh run'
}
}
}
}
我的奴隶B的名字是'laptop-hp',如Jenkinsfile所示
Jenkinsfile是否存在问题,或者我错过了从属B的某些设置?
问候 凯蒂
答案 0 :(得分:0)
Declarative Pipeline中的pipeline {}
块不能超过一个。正确的语法是在构建阶段之后立即添加测试阶段。然后为label
中的每个阶段定义参数docker {}
,以在相应的从站上运行。而且,只需在管道的顶层添加一次选项skipDefaultCheckout true
就足够了。
您的管道现在应如下所示:
pipeline {
agent none
options {
skipDefaultCheckout true
}
stages {
stage('build') {
agent {
docker {
image 'XYZ'
label 'slave-A'
args '-v /etc/localtime:/etc/localtime:ro'
}
}
steps {
echo '########################################## Building #########################################'
// trigger the build
sh 'scm-src/build.sh all-projects'
}
}
stage('prepare_test') {
agent {
docker {
image 'ABC'
label 'laptop-hp'
args '-v /home/jenkins/.ssh/:/home/jenkins/.ssh:ro -v /etc/localtime:/etc/localtime:ro'
}
}
steps {
echo '####################################### Prepare Test Environment ############################'
sh 'scm-src/test.sh prepare'
}
}
stage('test') {
agent {
docker {
image 'ABC'
label 'laptop-hp'
args '-v /home/jenkins/.ssh/:/home/jenkins/.ssh:ro -v /etc/localtime:/etc/localtime:ro'
}
}
steps {
echo '########################################## Testing ##########################################'
sh 'scm-src/test.sh run'
}
}
}
}