I am very new to jenkins and groovy. am grateful to be helped.
I am trying to create a job in jenkins to read an xml file for now which has to be updated later. However i am not able to parse the XML. kindly find the details below.
My XML below. This is converted to UTF-8 format using notepad++
My groovy script:
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"
(have tried def ofilesroot = new XmlParser().parseText(f)
also. it fails)
My jenkins log:
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
few things i have tried.
converted the xml to UTF-8 (with and without BOM) and have tried. Same Failure.
included and removed the at the beginning and tried, both results same failure.
no white spaces.
tried opening the xml file in an hexeditor to look for some hidden/special chars. Nothing found. tried again, same failure.
am totally lost. am i going wrong some where? please let me know what is missed out.
thank you..