+from __future__ import print_function
+
import logging
logging.basicConfig()
jobName = 'foo_job2'
xml = resource_string('examples', 'addjob.xml')
-print xml
+print(xml)
j = J.create_job(jobname=jobName, config=xml)
j2 = J[jobName]
-print j
+print(j)
# Delete job
J.delete_job(jobName)
# This example requires NestedViews plugin to be installed in Jenkins
# You need to have at least one job in your Jenkins to see views
+from __future__ import print_function
+
import logging
from pkg_resources import resource_string
else:
logger.info('View has been created')
-print 'top_view.views=', top_view.views.keys()
+print('top_view.views=', top_view.views.keys())
logger.info('Attempting to create view inside nested view')
sub_view = top_view.views.create('SubView')
if sub_view is None:
"""
An example of how to use JenkinsAPI to fetch the config XML of a job.
"""
+from __future__ import print_function
+
from jenkinsapi.jenkins import Jenkins
J = Jenkins('http://localhost:8080')
jobName = 'create_fwrgmkbbzk'
config = J[jobName].get_config()
-print config
+print(config)
"""
Extract version information from the latest build.
"""
+from __future__ import print_function
+
from jenkinsapi.jenkins import Jenkins
return lgb.get_revision()
if __name__ == '__main__':
- print getSCMInfroFromLatestGoodBuild('http://localhost:8080', 'fooJob')
+ print(getSCMInfroFromLatestGoodBuild('http://localhost:8080', 'fooJob'))
+from __future__ import print_function
+
from jenkinsapi.view import View
from jenkinsapi.jenkins import Jenkins
+
J = Jenkins('http://localhost:8080')
-print J.items()
+print(J.items())
j = J['foo']
j = J.get_job("foo")
b = j.get_last_build()
-print b
+print(b)
mjn = b.get_master_job_name()
print(mjn)
+from __future__ import print_function
+
from jenkinsapi.api import search_artifact_by_regexp
import re
+from __future__ import print_function
+
from jenkinsapi.api import search_artifacts
jenkinsurl = "http://localhost:8080/jenkins"
"""
A lower-level implementation of copying a job in Jenkins
"""
+from __future__ import print_function
import requests
from jenkinsapi.jenkins import Jenkins
h = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.post(url, data='dysjsjsjs', headers=h)
-print response.text.encode('UTF-8')
+print(response.text.encode('UTF-8'))
A low level example:
This is how JenkinsAPI creates views
"""
+from __future__ import print_function
+
import requests
import json
}
# Try 1
result = requests.post(url, params=params, data=data, headers=headers)
-print result.text.encode('UTF-8')
+print(result.text.encode('UTF-8'))
+from __future__ import print_function
+
import json
import requests
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
form = {'json': json.dumps(toJson)}
response = requests.post(url, data=form, headers=headers)
- print response.text.encode('UTF-8')
+ print(response.text.encode('UTF-8'))
if __name__ == '__main__':
foo()
"""
A lower level example of how we login with authentication
"""
+from __future__ import print_function
from jenkinsapi import jenkins
J = jenkins.Jenkins("http://localhost:8080", username="sal", password="foobar")
J.poll()
-print J.items()
+print(J.items())
"""
jenkinsapi plugins
"""
+from __future__ import print_function
import logging
def __init__(self, url, jenkins_obj):
self.jenkins_obj = jenkins_obj
JenkinsBase.__init__(self, url)
- # print 'DEBUG: Plugins._data=', self._data
+ # print('DEBUG: Plugins._data=', self._data)
def get_jenkins_obj(self):
return self.jenkins_obj
+from __future__ import print_function
+
import random
import string
return ''.join(random.choice(string.ascii_lowercase) for i in range(length))
if __name__ == '__main__':
- print random_string()
+ print(random_string())
+from __future__ import print_function
+
import mock
import unittest
)
self.assertTrue(isinstance(req_return, dict))
- print req_return.get('data')
+ print(req_return.get('data'))
self.assertTrue(req_return.get('data'))
self.assertTrue(req_return['data'] == 'some data')
data='some data'
)
- print ae.exception.message
+ print(ae.exception.message)
self.assertTrue(ae.exception.message == "Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=")
@mock.patch.object(requests, 'get')
params={'param': 'value'}
)
- print ae.exception.message
+ print(ae.exception.message)
self.assertTrue(ae.exception.message == "Operation failed. url=None, headers=None, status=500, text=")
if __name__ == "__main__":
+from __future__ import print_function
+
import SimpleHTTPServer
import SocketServer
import logging
httpd = SocketServer.TCPServer(("", PORT), Handler)
-print "serving at port", PORT
+print("serving at port", PORT)
httpd.serve_forever()