1
我在postbuild-step中使用的腳本如下,我試圖從文件中提取MAVEN_VERSION並且它找不到文件遠程奴隸,但是當我執行相同的本地奴隸相同的工作正常, 所以我相信該插件需要更新,有一個VirtualChannel打開遠程工作區解析文件,我還沒有看過代碼,但如果有人有速戰速決,能有人幫助,這
環境細節
運行詹金斯1.625.3.1
Groovy的postbuild-插件 - 2.2.2
JDK1.8.0_72
Tomcat_8.0.30
在遠程從站上執行Groovy-Postbuild-Plugin失敗,抱怨文件未找到
import jenkins.util.*;
import jenkins.model.*;
def thr = Thread.currentThread();
def currentBuild = thr?.executable;
def workspace = currentBuild.getModuleRoot().absolutize().toString();
def project = new XmlSlurper().parse(new File("$workspace/pom.xml"))
def param = new hudson.model.StringParameterValue("MAVEN_VERSION", project.version.toString())
currentBuild.addAction(new hudson.model.ParametersAction(param));
錯誤日誌 -
ERROR: Failed to evaluate groovy script.
java.io.FileNotFoundException: /prod/jenkins/test-slave/workspace/MYProjectBuild/pom.xml (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:160)
at groovy.util.XmlSlurper$parse.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Script1.run(Script1.groovy:6)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:580)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:618)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:166)
at org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.perform(GroovyPostbuildRecorder.java:362)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:726)
at hudson.model.Build$BuildExecution.post2(Build.java:185)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:671)
at hudson.model.Run.execute(Run.java:1766)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:408)
而不是Thread.currentThread你可以使用manager.build。至於獲取遠程文件,請看一下hudson.FilePath;你可以從currentBuild.builtOn.computer.channel或currentBuiild.workspace.channel獲取ComputerChannel – izzekil
你可以提供一些關於使用manager.build()的更多細節,還可以指點我一些文檔,在那裏我可以閱讀有關groovy和詹金斯業務,我是新常規,並想了解它。 – mv012004