I'm trying to send a json variable ( {{parameter_var}} ) to a Jenkins job from Ansible using a curl call. Here is the task I'm using:
- name: Call Jenkins Job
shell: curl -H "crumb:{{ response.json.crumb }}" '{{ jenkinshost }}/job/{{ jenkinsjob }}/buildWithParameters?token={{ jenkinstoken }}' --data-urlencode json='{"parameter": [{"name":"parameter", "value":\""{{ parameter_var }}"\"}]}'
The error I'm getting is:
Syntax Error while loading YAML.\n mapping values are not allowed in this context
Ansible says the issue is:
YAML thought it was looking for the start of a\nhash/dictionary and was confused to see a second "{".
It seems that instead of accepting {{ parameter_var }} as a variable, it's trying to read it as just a value of "{{ parameter_var }}". I tried a few ways of adding or escaping quotes, but can't seem to figure out what Ansible/YAML is looking for. Am I just adding my quotes wrong, or can I just not send a variable using this method?
I printed out my {{ parameter_var }}. There's nothing unusual about it, so I don't think that's the issue:
{
"msg": {
"msg": "All items completed",
"changed": false,
"results": [
{
"content_length": "142",
...
} ...
}
The goal I'm trying to accomplish is to set parameter "parameter" in Jenkins to the value of {{ parameter_var }}
Here's where I found the syntax for sending the json to Jenkins: https://wiki.jenkins.io/display/JENKINS/Remote+access+API