remote access api and curl

10 views
Skip to first unread message

gessn...@gmail.com

unread,
Sep 14, 2016, 10:50:57 AM9/14/16
to Jenkins Users

I am trying to write a bash script to start a build on Jenkins. It works but the problem I am having is with passing parameter values.

I have: curl -X POST $Server -d token='MyToken' --data-urlencode json='{ ... }' and I want to replace the json='{...}' with a variable as in json=$Params where my json string is '{"parameters": [{"name":"USER", "value":"Tim"}]}'

This json string works when I specify it on the command line but not however when I put it in a variable. With the variable I get a stack trace and html - several screens worth.

When assigning to a variable a have tried several things though currently I have Params="{\"parameters\": [{\"name\":\"USER\", \"value\":\"Tim\"}]}"

It appears that it can't parse my json when I pass it through $Params but can in the other case.

What I am trying to do is get the user name passed in from a perforce trigger, then get that users email address. I have that working assigning to a variable @UserEMail. I then want to pass that in the json value. I haven't gotten to the point of replacing "Tim" with the value from @UserEmail.

Thank you for any help.

gessn...@gmail.com

unread,
Sep 14, 2016, 11:59:10 AM9/14/16
to Jenkins Users
I have made progress - using --data-urlencode json="$Params" will trigger the build though the parameters I send over - P4USER and EMAIL_ADDR are blank in the environment variables.

gessn...@gmail.com

unread,
Sep 14, 2016, 12:01:28 PM9/14/16
to Jenkins Users
More progress - I changed buildWithParameters to just build and it seems to work. No to replace strings with variables in the JSON string

Tim


On Wednesday, September 14, 2016 at 7:50:57 AM UTC-7, gessn...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages