I have the following groovy code in my jenkins pipeline job:
stage 'Get ddplist file for rel:' + item
myUrl ='http://mygitrepo.net/cgit/testing.git/plain/' +item + '.ddplist '
def data = new URL(myUrl).getText()
echo data
That returns the following output:
Entering stage Get ddpfile for rel:20170815.2 Proceeding [Pipeline] echo source=http://mygitrepo.net/cgit/repo1/snapshot/source-v20170815.2.tar.bz2 ltp=http://mygitrepo.net/cgit/repo2.git/snapshot/ltp-v20170815.1.tar.bz2 car=http://mygitrepo.net/cgit/repo3.git/snapshot/car-v20170815.1.tar.bz2
Question
How can I "query" this string to find out what the source file is or the ltp file?
What I've tried so Far
I tried adding the following two lines of code, like this:
def mymap = data.split("\n").collect{ it.split("=", 2) }.collectEntries()
echo mymap
But I'm getting the error:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods getText java.net.URL
at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectStaticMethod(StaticWhitelist.java:190)
Any suggestions would be appreciated.
EDIT 1
SO while the answer I chose below technically worked in the sense that it displayed the echo results.. I wasn't actually able to use the data anywhere because of serialization errors. Specifically I was getting the following output from jenkins:
[ssh-agent] Started.
[Pipeline] {
[Pipeline] echo
SRC: http://mygitrepo.net/cgit/repo1/snapshot/abc.tar.bz
[Pipeline] echo
INV: http://mygitrepo.net/cgit/repo2/snapshot/def.tar.bz2
[Pipeline] echo
CTG: testvalue
[Pipeline] echo
ANSIBLE_HOST: 10.1.1.1
[Pipeline] echo
ANSIBLE_DIR: /etc/ansible/mytestdirectory
[Pipeline] stage (Copy new code to Ansible)
Entering stage Copy new code to Ansible
Proceeding
[Pipeline] sh
[workspace] Running shell script
[Pipeline] }
[Pipeline] }
[Pipeline] End of Pipeline
java.io.NotSerializableException: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream
using the following code:
myUrl = "http://mygitrepo/cgit/testing.git/plain/" + item + ".dpplist"
// Requires script approval
def inStream = new URL(myUrl).openStream() //open up the dpplist for this release
def prop = new Properties()
prop.load(inStream) //create a properties object out of it.
src= prop.src
inv= prop.inv
ctg=prop.ctg
sshagent(['johndoe']) {
rbdbox(ANSIBLE_HOST,ANSIBLE_DIR, src, inv, ctg)
}
def rbdbox(ANSIBLE_HOST,ANSIBLE_DIR, SRC, INV, CTG) {
echo "SRC: ${SRC}"
echo "INV: ${INV}"
echo "CTG: ${CTG}"
echo "ANSIBLE_HOST: ${ANSIBLE_HOST}"
echo "ANSIBLE_DIR: ${ANSIBLE_DIR}"
stage 'Copy new code to Ansible'
sh "ssh -A root@${ANSIBLE_HOST} 'rm -rf ${ANSIBLE_DIR}/*'"
}
So to get it to work i had to change the code to
myUrl = "http://mygitrepo.net/cgit/testing.git/plain/" + item + ".ddplist "
// Requires script approval
def prop = new Properties()
prop.load(new URL(myUrl).openStream())
And then everything started to work. In other words i'm not defining instream.