Reputation: 6305
I wrote the following function which is loaded to my pipeline:
def userTrigger() {
[$class: 'UsernamePasswordMultiBinding', credentialsId: jenkins_creds, usernameVariable: 'J_USER', passwordVariable: 'J_PASS'],
]){
cmd = "curl -s -u \${J_USER}:\${J_PASS} \${env.BUILD_URL}api/json | python -mjson.tool | grep userId | awk '{print \$2}' | tr -d '"|,' "
def ut = sh(returnStdout: true, script: cmd)
return ut
}
}
The result should be the username of the one who triggered the build, before cleaning the output it looks like so:
"userId": "itaig",
Basically, this:
awk -F'"' '{print $4}'
would also give me the required output but i'm not sure how to escape chars in this statement too.
When I run the job, I get the following error:
java.io.NotSerializableException: org.codehaus.groovy.control.ErrorCollector
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
I'm pretty much sure it has something to do with my tries of escaping the relevant characters but I have a feeling that I haven't done it right, I've tried escaping the (") in the end of the cmd line but to no avail.
Can you try and find my issue?
Upvotes: 1
Views: 760
Reputation: 13571
What is that right parenthesis and right bracket closing on line #3?
]){
It might be more of the double-quote vs single-quote then the escaping of characters - make sure they are are pairing up nicely.
Upvotes: 2