-
Bug
-
Resolution: Unresolved
-
Minor
-
None
Exception with Creating Jenkins job with Customized Template using python-jenkins API
--------------------------------------------------------------------------------------------------------------
Python Code for to create jenkins Job
-----------------------------------------------
import jenkins
server = jenkins.Jenkins('http://<jenkins-ip>:8080', username='admin', password='admin',timeout=1000)
job = server.create_job(name="HelloWorld", config_xml='Template.xml')
print( job)
--------------------------------------------
Exception
-------------------------------------------
C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\python.exe "D:/MyWorkspace/Python Workspace/HelloWorld/Test.py"
Traceback (most recent call last):
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\site-packages\jenkins_init_.py", line 431, in jenkins_open
response = urlopen(req, timeout=self.timeout).read()
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 532, in open
response = meth(req, response)
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 570, in error
return self._call_chain(*args)
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Server Error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/MyWorkspace/Python Workspace/HelloWorld/Test.py", line 4, in <module>
job = server.create_job(name="HelloWorld", config_xml='Template.xml')
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\site-packages\jenkins_init_.py", line 992, in create_job
config_xml.encode('utf-8'), DEFAULT_HEADERS))
File "C:\Users\SRI_14\AppData\Local\Programs\Python\Python36\lib\site-packages\jenkins_init_.py", line 448, in jenkins_open
e.code, e.msg)
jenkins.JenkinsException: Error in request. Possibly authentication failed [500]: Server Error
Process finished with exit code 1
i get the same error creating a job:
#https://python-jenkins.readthedocs.io/en/latest/index.html
#pip install python-jenkin
import sys
import jenkins
def getServer(address="192.168.1.6",port='8081',timeout=5,user="admin",password="admin"):
{{ server=jenkins.Jenkins('http://'address':'+port, username=user, password=password)}}
{{ if not server.wait_for_normal_op(30): print("Jenkins failed to be ready in sufficient time"); exit(2)}}
{{ return server}}
def names(l,name="name"): return [x[name] for x in l]
def getInfo(server):
{{ user=server.get_whoami()}}
{{ version=server.get_version()}}
{{ print('Hello %s from Jenkins %s' % (user['fullName'], version))}}
{{ print(server.jobs_count(),"jobs.")}}
{{ jobs=server.get_jobs()}}
{{ print('jobs:',names(jobs))}}
{{ plugins=server.get_plugins_info()}}
{{ print(len(plugins),'plugins.')}}
{{ #print(len(plugins),'plugins:',names(plugins,name='shortName'))}}
{{ return jobs}}
def main():
{{ if len(sys.argv)<2: raise Exception("user and password please")}}
{{ server=getServer(user=sys.argv[1],password=sys.argv[2])}}
{{ jobs=getInfo(server)}}
{{ try: server.create_node('foo')}}
{{ except Exception as e: print(str(e)[:80])}}
if _name_ == "_main_": main(){{}}
}}{{$ python jen.py raz 11213
Hello Ray Tayek from Jenkins 2.293
4 jobs.
jobs: ['fs-agent-job-1', 'fs-agent-job-2', 'fs-python-1', 'p2 inline']
133 plugins.
Error in request. Possibly authentication failed [500]: Server Error
{{ <!DOC}}