jenkinsapi
jenkinsapi copied to clipboard
unable to post buildWithParameters
ISSUE TYPE
- How to post buildWithParameters data with multiple values
Jenkinsapi VERSION: 0.3.11
Jenkins VERSION: 2.204.2
SUMMARY
I did curl, it creates the job but unable to pass the variables. Here is the curl command:
curl -X POST -v https://JENKINS_SERVER/job/JOB_NAME/buildWithParameters --user joe:1139 --data-urlencode json='{"parameter": [{"name": "registration_action","value": "DNS_only"},{"name": "entries","value": "add, hostname01.local.example.com, 192.168.1.1/24\nremove, hostname01.local.example.com, 192.168.1.1/24/\n" }]}'
stringdata = "add, hostname01.local.example.com, 192.168.1.1/24\nremove, hostname01.local.example.com, 192.168.1.1/24/\n"
params = {"name": "registration_action", "value": "DDNS_only", \
"name": "Note:", "value": "test02", \
"name": "entries","value": stringdata }
j.jenkins_login().build_job('DDNS_Tool_v1', params=params)
Fail to do post, not sure where is the issue. Thank you for your help in advance.
Any exception produced?
it create a job with empty field
{"_class":"hudson.model.FreeStyleBuild","actions":[{"_class":"hudson.model.ParametersAction","parameters":[{"_class":"hudson.model.StringParameterValue","name":"registration_action","value":"IPAM and DNS"},{"_class":"hudson.model.StringParameterValue","name":"entries","value":""}]}
Here is code I ran:
class JENKINSLOGIN(object):
def __init__(self, url, username, pswd, useCrumb=True, ssl_verify=False):
self.jenkinsurl = url
self.username = username
self.password = pswd
self.useCrumb = useCrumb
self.ssl_verify = ssl_verify
def jenkins_login(self):
server = Jenkins(self.jenkinsurl, username=self.username, password=self.password, useCrumb=self.useCrumb, ssl_verify=self.ssl_verify)
return server
url = "https://localhost:8080"
j = JENKINSLOGIN(url, user, pswd)
job = j.jenkins_login().create_job(jenkins_job, params)
Output:
jenkinsapi.custom_exceptions.JenkinsAPIException: Operation failed. url=https://localhost:8080/createItem?name=coreinfra%2Fjob%2Fprod%2Fjob%2FDNStool%2Fjob%2FDDNS_Tool_v1, data={'parameter': [{'name': 'registration_action', 'value': 'DDNS_only'}, {'name': 'Note:', 'value': 'test02'}, {'name': 'entries', 'value': 'add, hostname02.localhost, 192.168.1.2/24\nadd, hostname01.localhost, 192.168.1.1/24\n'}]}, headers={'Content-Type': 'text/xml', 'Jenkins-Crumb': '8bfd1f3f77af7abcff904d4027def582'}, status=400, text=b'\n
I too face issue similar to this.
import jenkinsapi #from jenkinsapi.job import * from jenkinsapi.jenkins import Jenkins import os.path
data_file = open('test-data.txt', 'r') build_params = {"IMAGE":"test-image","test_URL":"www.test.com/test","AREA_NAME":"test","PARA":"4","TYPE":"custom"}
jenkins_url = "https://jenkins-pc.test.cci.test.com" username = "test_user" password = "passcode"
server = Jenkins(jenkins_url, username=username, password=password, timeout = 1200, lazy = True) job = "tenant/sec/value-Check" new_job = server[job] running_job_object = new_job.invoke(block=True, build_params=build_params, files={'tests.custom': data_file}) data_file.close()
TRACEBACK
Traceback (most recent call last):
File "executeJob.py_t", line 23, in
you may want to try https://api4jenkins.readthedocs.io/en/latest/index.html