简体   繁体   中英

Python-Jenkins build job not working

I want to trigger an build Job in Jenkins through python-jenkins package. I am able to connect and get jenkins version and last successfull build number but when i request for a build job it gives an authentication error.

>>> import jenkins
>>> server = jenkins.Jenkins('http://jenkinshost', 'ahmes', 'mytoken')
>>> server.build_job('job-name', {'param1':'testvalue'},'mytoken')

Below is the error :

File "C:\\Python27\\lib\\site-packages\\jenkins__init__.py", line 914, in build_job self.build_job_url(name, parameters, token), b'')) File "C:\\Python27\\lib\\site-packages\\jenkins__init__.py", line 361, in jenkins_open e.code, e.msg) JenkinsException: Error in request. Possibly authentication failed [500]: Server Error

I was able to get the last build number there shouldn't be a authentication error .

Worked on Jenkins 2.7.1 + python 2.7.10 as follows:

from jenkinsapi.jenkins import Jenkins
server = Jenkins(jenkinsUrl, userName, userToken)

trigger with no parameters or use default parameters values:

server.build_job(jobName)

trigger with parameters:

server.build_job('groovy-post-build',{'PARAM1':'value1', 'PARAM2':'value2'})

(PARAM1 and PARAM2 are the names of the parameters in the job)

note: make sure that the user has permission to trigger that job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM