2017-02-22 98 views
1

詹金斯版本= 2.19 詹金斯多枝流水線插件版本= 2.92詹金斯管道有條件的階段成功,但詹金斯表明打造爲失敗

我有一個Jenkinsfile基於分支少數有條件的階段。

下面是一個修改的我Jenkinsfile的簡潔版的緣故

node { 
    stage('Checkout') { 
     checkout scm 
    } 

    stage('Clean Verify') { 
     sh 'mvn clean verify' 
    } 

    if (env.BRANCH_NAME == "develop") { 
     stage('Docker') { 
      sh 'mvn docker:build -DpushImage' 
     } 
    } 
} 

我現在用的多分支管道插件。

它成功檢測並構建了我的所有分支機構。

我遇到的問題是,所有構建報告都失敗了,即使我在每個階段懸停報告「成功」。

我附上了一張圖片,顯示我想要運行的兩個階段已經運行並完成成功的功能分支,但您可以看到該構建實際報告爲失敗。

Jenkins failed build

我得到發展的分支以及完全相同的結果 - 它成功地執行泊塢階段,但生成報告失敗。

我的期望是每個分支都會報告成功,因爲該分支運行的階段都已通過。

編輯1

這裏的生成日誌的末尾(我希望這是足夠的,因爲我不想挑出所有的私人信息,但讓我知道,如果需要的話)

[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 30.459 s 
[INFO] Finished at: 2017-02-21T15:13:02+11:00 
[INFO] Final Memory: 84M/769M 
[INFO] ------------------------------------------------------------------------ 
[Pipeline] } 
[Pipeline] // stage 
[Pipeline] } 
[Pipeline] // node 
[Pipeline] sh 
Required context class hudson.FilePath is missing 
Perhaps you forgot to surround the code with a step that provides this, such as: node 
[Pipeline] End of Pipeline 
org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing 
    at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:253) 
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:179) 
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:126) 
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108) 
at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source) 
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) 
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) 
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151) 
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21) 
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115) 
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:103) 
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149) 
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146) 
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:16) 
at WorkflowScript.run(WorkflowScript:93) 
at ___cps.transform___(Native Method) 
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57) 
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109) 
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82) 
at sun.reflect.GeneratedMethodAccessor501.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72) 
at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21) 
at com.cloudbees.groovy.cps.Next.step(Next.java:58) 
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154) 
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18) 
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33) 
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30) 
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) 
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30) 
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163) 
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:328) 
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:80) 
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:240) 
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:228) 
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112) 
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) 
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 
+0

你能告訴我們什麼在生成日誌? –

回答

5

因此,仔細觀察日誌文件後,它幫助我追蹤了這個問題。

值得注意的是,單擊構建階段來查看日誌是什麼扔我 - 這是我一直在做。當我真正到了全控制檯日誌輸出我看到了有關的錯誤:

Required context class hudson.FilePath is missing 
Perhaps you forgot to surround the code with a step that provides this, such as: node 

下的節點{}部分,我有我有部署了一個聲明:

def branch = readFile('branch').trim() 
if (branch == master) { 
    ... 
} 

的問題是, readFile語句是在節點之外定義的。

答案是將readFile語句放在節點{}部分中。

+0

這必須在節點的上下文中執行的事實是一個非常重要的細節。這就是讓我絆倒的原因。 – Brandon

1

sh命令最後沒有用引號關閉。

+0

謝謝你指出。這只是我的SO帖子中的一個錯字,儘管不在Jenkins文件本身中 – wimnat