I'm having trouble with Jenkins' API while using Python 3.10.2 with Ubuntu LTS 20.4 with Jenkins 2.361 with api4jenkins 1.11 as the wrapper for the API.
My main trouble is passing parameters to a Task. I'm able to start the task, and I'm doing as the examples indicate to pass the parameters, but the taks' execution don't print the parameters.
Jenkins has a global security configuration for each user, this is the one for the user that's starting the task:
My Task is called Prueba4, the task security configuration is this one:
Right now, I only have the parameter client:
I also enabled script execution:
The only step is this shell command:
echo Hello
echo $USER
echo $cliente
With Python I'm doing this:
from api4jenkins import Jenkins
j = Jenkins('http://localhost:8080/', auth=('my_user', 'mypass'))
j.build_job('Prueba4', client="my cliente", token="my_token", delay='1sec')
So I can't find the problem that the line echo $client does not show the parameter I passed. Adding print to api4jenkins I was able to identify that it pass this kwards:
method: POST
url +: http://localhost:8080/job/Prueba4/buildWithParameters
kwards: {'params': {'client': 'my_client'}, 'token': 'my_token', 'delay': '1sec'}, 'headers': {'Jenkins-Crumb': '81bec758701d0783a68f3ad4050e42c647953834f1c552120b194d6e8b989f52'}}
I don't know what I' doing wrong. This is an execution started with python that doesn't print the parameter:
I tried with CURL and Python's Request library, but I'm not able to make a request with them yet.
Hope someone can help me. Thanks
EDIT: Ok, I was making a dumb mistake, I really needed to pass a dictionary and I was adding the variable directly, I forgot to send it as a string, the true reason why Jenkins was not accepting the request.