简体   繁体   English

Jenkins访问文件在工作区中-Groovy PostBuild

[英]Jenkins access file in workspace - groovy postbuild

I am trying to access an XML config file in a Jenkins workspace and parse it with the Groovy XmlSlurper via the groovy post build plugin. 我正在尝试访问Jenkins工作区中的XML配置文件,并通过groovy发布构建插件将其与Groovy XmlSlurper解析。 I am able to access the File by creating a FilePath object, but XmlSlurper is expecting either a File object or a String. 我可以通过创建FilePath对象来访问文件,但是XmlSlurper期望使用File对象或String。 There is a toString method for FilePath, but it looks like it is deprecated. FilePath有一个toString方法,但似乎已弃用。

Has anyone done something similar to this? 有人做过类似的事情吗?

def project = manager.build.project
def fp = project.getWorkspace().child("summary.xml");

if (fp.exists()) {
        def perfData = new XmlSlurper().parse(fp)
}

您应该可以使用readToString

    def perfData = new XmlSlurper().parseText(fp.readToString())

I see FilePath has a 我看到FilePath有一个

 InputStream read()
 String readToString()

Either one of those should get you to the format you need. 其中任何一种都可以使您获得所需的格式。 InputStream.getText() in Groovy returns the content of the stream. Groovy中的InputStream.getText()返回流的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM