我在构建的Jenkinsfile管道中遇到以下错误:
java.lang.NullPointerException
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
主要是这里的问题是我不确定到底发生了什么。既然提到的只是空指针错误,所以我不能完全确定,也找不到更具体的内容。
这是我的Jenkins文件:
#!groovy
node {
withEnv(["WORKSPACE=${pwd()}"]) { //Setting Workspace to the current directory
stage('Clone repository...') {
checkout scm //Let checkout automagically handle pulling in all the names we need and whatnot
}
stage('Building WAR...') {
step(withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'Maven 3.6.0') {
// Run the maven build
sh 'mvn clean install' //Same as running on local
sh 'mv ${WORKSPACE}/target/QUserService.war ${WORKSPACE}/target/QUserService_War-QUserService-${BRANCH_NAME}-${BUILD_NUMBER}.war'
//For above line, 'mv' is the Linux command to rename/move files, which is needed for the UCD script
}
// withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs reports...
)
}
}
}
答案 0 :(得分:1)
所以-首先,您不需要定义WORKSPACE。它由詹金斯(Jenkins)为您定义。您可以通过在Linux代理上运行sh'set'来说服自己。
接下来,您无需检出项目。它已经在那里(假设您正在使用管道项目)。
接下来,您不需要将withMaven放在步骤调用中。在脚本化管道中,阶段中的内容是常规脚本。不需要步骤。
node {
stage('Building WAR...') {
withMaven(
maven: 'Maven 3.5.0') {
// Run the maven build
sh 'mvn clean install' //Same as running on local
}
}
我采取了行动步骤并发表评论只是为了使其更清楚。
我没有得到空指针错误。查看是否删除步骤呼叫并删除步骤呼叫使NPE消失。如果没有,我建议附加控制台输出,以尝试查看发生这种情况的地方。