From: Salim Fadhley Date: Mon, 17 Jun 2013 00:00:08 +0000 (+0100) Subject: more examples sorted X-Git-Tag: v0.2.23~126^2~51 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b09c959d4720fd9430ab6db89322688c960552a;p=tools%2Fpython-jenkinsapi.git more examples sorted --- diff --git a/examples/how_to/readme.rst b/examples/how_to/readme.rst new file mode 100644 index 0000000..9dbb11f --- /dev/null +++ b/examples/how_to/readme.rst @@ -0,0 +1,5 @@ +"How To..." examples +==================== + +This directory contains a set of examples or recipes for common tasks in +JenkinsAPI. \ No newline at end of file diff --git a/examples/low_level/copy_a_job.py b/examples/low_level/copy_a_job.py new file mode 100644 index 0000000..3eef8b6 --- /dev/null +++ b/examples/low_level/copy_a_job.py @@ -0,0 +1,23 @@ +""" +A lower-level implementation of copying a job in Jenkins +""" + +import requests +from jenkinsapi.jenkins import Jenkins +from pkg_resources import resource_string +from jenkinsapi_tests.test_utils.random_strings import random_string + +J = Jenkins('http://localhost:8080') +jobName = random_string() +jobName2 = '%s_2' % jobName + +url = 'http://localhost:8080/createItem?from=%s&name=%s&mode=copy' % ( + jobName, jobName2) + +xml = resource_string('examples', 'addjob.xml') +j = J.create_job(jobname=jobName, config=xml) + + +h = {'Content-Type': 'application/x-www-form-urlencoded'} +response = requests.post(url, data='dysjsjsjs', headers=h) +print response.text.encode('UTF-8') diff --git a/examples/low_level/create_a_view_low_level.py b/examples/low_level/create_a_view_low_level.py new file mode 100644 index 0000000..56075e8 --- /dev/null +++ b/examples/low_level/create_a_view_low_level.py @@ -0,0 +1,21 @@ +""" +A low level example: +This is how JenkinsAPI creates views +""" +import requests +import json + +url = 'http://localhost:8080/createView' + +str_view_name = "blahblah123" +params = {}# {'name': str_view_name} +headers = {'Content-Type': 'application/x-www-form-urlencoded'} +data = { + "name": str_view_name, + "mode": "hudson.model.ListView", + "Submit": "OK", + "json": json.dumps({"name": str_view_name, "mode": "hudson.model.ListView"}) +} +# Try 1 +result = requests.post(url, params=params, data=data, headers=headers) +print result.text.encode('UTF-8') diff --git a/examples/low_level/example_param_build.py b/examples/low_level/example_param_build.py new file mode 100644 index 0000000..0177012 --- /dev/null +++ b/examples/low_level/example_param_build.py @@ -0,0 +1,18 @@ +import json +import requests + +def foo(): + """ + A low level example of how JenkinsAPI runs a parameterized build + """ + toJson = {'parameter':[{'name':'B', 'value':'xyz'}]} + url = 'http://localhost:8080/job/ddd/build' + #url = 'http://localhost:8000' + 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') + +if __name__ == '__main__': + foo() + diff --git a/examples/low_level/login_with_auth.py b/examples/low_level/login_with_auth.py new file mode 100644 index 0000000..189be69 --- /dev/null +++ b/examples/low_level/login_with_auth.py @@ -0,0 +1,11 @@ +""" +A lower level example of how we login with authentication +""" + +from jenkinsapi import jenkins + + +J = jenkins.Jenkins("http://localhost:8080", username = "sal", password = "foobar") +J.poll() + +print J.items() diff --git a/examples/low_level/readme.rst b/examples/low_level/readme.rst new file mode 100644 index 0000000..50a2d9f --- /dev/null +++ b/examples/low_level/readme.rst @@ -0,0 +1,4 @@ +Low-Level Examples +================== + +These examoples are intended to explain how JenkinsAPI performs certain functions. While developing JenkinsAPI I created a number of small scripts like these in order to figure out the correct way to communicate. Ive retained a number of these as they provide some insights into how the various interfaces that Jenkins provides can be used. \ No newline at end of file