Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins 工作流步骤中出现文件空指针错误_Jenkins_Groovy_Jenkins Pipeline - Fatal编程技术网

Jenkins 工作流步骤中出现文件空指针错误

Jenkins 工作流步骤中出现文件空指针错误,jenkins,groovy,jenkins-pipeline,Jenkins,Groovy,Jenkins Pipeline,我在构建Jenkins文件管道时遇到以下错误: 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.plug

我在构建Jenkins文件管道时遇到以下错误:

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
这里的问题主要是,我不确定到底发生了什么。因为它提到的只是一个空指针错误,所以我不能确切地确定,也找不到任何更具体的

这是我的詹金斯档案:

#!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...
        )
        }
     }
}

所以-首先,您不需要定义工作空间。它是由詹金斯为你定义的。您可以通过在linux代理上运行sh“set”来说服自己

接下来,您不需要签出项目。它已经存在了(假设您使用的是管道项目)

接下来,不需要将withMaven放在step调用中。在脚本化管道中,阶段中的内容是groovy脚本。步骤不是必需的

node {
        stage('Building WAR...') {
            withMaven(
                    maven: 'Maven 3.5.0') {
                // Run the maven build
                sh 'mvn clean install' //Same as running on local
        }
}
我采取了行动步骤并发表了评论,只是为了让它更清楚


我没有得到空指针错误。查看移除step调用和移除step调用是否会使NPE消失。如果没有,我建议附加控制台输出以尝试查看发生这种情况的地方。

啊,该死,我实际上已经找到了答案,并打算自己发布,但你也打败了我!是的,问题在于围绕withMaven()调用的步骤()。一旦我删除了它,我的问题就解决了!