wim*_*nat 10 jenkins jenkins-pipeline
Jenkins版本= 2.19 Jenkins Multibranch Pipeline插件版本= 2.92
我有一个基于分支的几个条件阶段的Jenkins文件.
这是为了我的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'
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用multibranch管道插件.
它成功检测并构建了我的所有分支.
我遇到的问题是所有构建报告都失败了,即使我在每个阶段都悬停它报告"成功".
我附加了一个显示功能分支的图像,其中我想运行的两个阶段已经运行并成功完成,但您可以看到构建实际报告为失败.
我得到了与开发分支完全相同的结果 - 它成功执行了Docker阶段,但构建报告失败了.
我的期望是每个分支都会报告成功,因为该分支的所有阶段都已通过.
编辑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
Run Code Online (Sandbox Code Playgroud)
wim*_*nat 25
因此,在仔细查看日志文件后,它帮助我找到问题所在.
值得注意的是点击构建阶段查看日志是什么让我 - 这就是我一直在做的事情.当我真正进入完整的控制台日志输出时,我看到了以下错误:
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
Run Code Online (Sandbox Code Playgroud)
在我所拥有的节点{}部分下面,我有一个部署声明:
def branch = readFile('branch').trim()
if (branch == master) {
...
}
Run Code Online (Sandbox Code Playgroud)
问题是readFile语句是在节点之外定义的.
答案是将readFile语句放在node {}部分中.
Sai*_*tes 11
我知道这很老,但是我遇到了一个类似的问题,它使用了声明式管道并落在这里。事实证明,我试图在块中使用a sh来设置environment变量pipeline,但我的主要对象agent是none,即:
pipeline {
agent none
environment {
VERSION = sh(returnStdout: true, script: 'git describe --tags')
}
}
Run Code Online (Sandbox Code Playgroud)
这导致了同样的错误Required context class hudson.FilePath is missing。它移动到stage与agent预期一样。
我的错误解决方案 Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
是:
#!/usr/bin/env groovy
import hudson.model.*
node('master') {
sh("your shell script")
}
Run Code Online (Sandbox Code Playgroud)
就我而言,它突然停止工作,并出现错误:
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
Run Code Online (Sandbox Code Playgroud)
原因是该节点简单地关闭了。必须重新启动它并重新启动其代理(它是从属)。
| 归档时间: |
|
| 查看次数: |
57496 次 |
| 最近记录: |