我是jenkins和groovy的新手。我很感激能得到帮助。
我正在尝试在jenkins中创建一个作业,以便立即读取xml文件,该文件必须在以后更新。但是,我无法解析XML。请在下面找到详细信息。
我的XML在下面。使用notepad ++
将其转换为UTF-8格式我的常规剧本:
import java.io.*
import groovy.xml.*
println "---------------------------------------------------------------"
println "UPDATE TESTS CONFIG & DATA"
def xmlConfFile = System.getenv('workspace') + "\\" + "test\\xx.xx.xx.xx.test.xx\\xx\\testconfig.xml"
println xmlConfFile
File f = new File(xmlConfFile);
if (f.exists())
println "file exists..."
else
println "NO FILE"
def ofilesroot = new XmlParser().parseText(xmlConfFile)
println "ROOT obtained"
(已尝试def ofilesroot = new XmlParser().parseText(f)
。它失败了)
我的詹金斯日志:
Started by user Ashok
[EnvInject] - Loading node environment variables.
[EnvInject] - Preparing an environment for the build.
[EnvInject] - Keeping Jenkins system variables.
[EnvInject] - Keeping Jenkins build variables.
[EnvInject] - Injecting contributions.
Building remotely on group_sap-dp01-win-p (swing toe1) in workspace C:\workspace\GRILLS-TestGroovy
[GRILLS-TestGroovy] $ C:\tools\hudson.plugins.groovy.GroovyInstallation\Groovy_2.0.5\bin\groovy.bat C:\workspace\GRILLS-TestGroovy\hudson2255567075077296168.groovy
---------------------------------------------------------------
UPDATE TESTS CONFIG & DATA
C:\workspace\GRILLS-TestGroovy\test\xx.xx.xx.xx.xx.fragment\testConfig\testconfig.xml
file exists...
[Fatal Error] :1:1: Content is not allowed in prolog.
Caught: org.xml.sax.SAXParseException: Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at hudson2255567075077296168.run(hudson2255567075077296168.groovy:16)
Build step 'Execute Groovy script' marked build as failure
[BFA] Scanning build for known causes...
[BFA] Done. 0s
Finished: FAILURE
我尝试过的一些事情。
将xml转换为UTF-8(有和没有BOM)并尝试过。相同的失败。
包含并删除了开头并尝试了,两个结果都失败了。
没有空格。
尝试在hexeditor中打开xml文件以查找一些隐藏/特殊字符。什么都没找到。再次尝试,同样的失败。