From: Salim Fadhley Date: Sun, 16 Jun 2013 23:55:37 +0000 (+0100) Subject: added a bunch of stuff in a new location X-Git-Tag: v0.2.23~126^2~52 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29dbcb7334acf94d20fdb28a24cf061fe7387228;p=tools%2Fpython-jenkinsapi.git added a bunch of stuff in a new location --- diff --git a/examples/how_to/create_views.py b/examples/how_to/create_views.py new file mode 100644 index 0000000..6e8df27 --- /dev/null +++ b/examples/how_to/create_views.py @@ -0,0 +1,38 @@ +import logging + +from jenkinsapi.view import View +from jenkinsapi.jenkins import Jenkins + +log_level = getattr(logging, 'DEBUG') +logging.basicConfig(level=log_level) +logger = logging.getLogger() + +jenkins_url = "http://192.168.1.64:8080/" +api = Jenkins(jenkins_url) + +# Create ListView in main view +logger.info('Attempting to create new view') +new_view = api.create_view('SimpleListView') +logger.info('new_view is %s' % new_view) +if new_view == None: + logger.error('View was not created') +else: + logger.info('View has been created') + +logger.info('Attempting to create view that already exists') +if not api.create_view('SimpleListView'): + logger.info('View was not created') +else: + logger.error('View has been created') + +logger.info('Attempting to delete view that already exists') +if not api.delete_view('SimpleListView'): + logger.error('View was not deleted') +else: + logger.info('View has been deleted') + +logger.info('Attempting to delete view that does not exist') +if api.delete_view('SimpleListView'): + logger.error('View has been deleted') +else: + logger.info('View was not deleted') diff --git a/examples/how_to/get_config.py b/examples/how_to/get_config.py new file mode 100644 index 0000000..7a10394 --- /dev/null +++ b/examples/how_to/get_config.py @@ -0,0 +1,11 @@ +""" +An example of how to use JenkinsAPI to fetch the config XML of a job. +""" +from jenkinsapi.jenkins import Jenkins +J = Jenkins('http://localhost:8080') +jobName = 'create_fwrgmkbbzk' + +config = J[jobName].get_config() + +print config + diff --git a/examples/how_to/query_a_build.py b/examples/how_to/query_a_build.py new file mode 100644 index 0000000..c705e6d --- /dev/null +++ b/examples/how_to/query_a_build.py @@ -0,0 +1,32 @@ +from jenkinsapi.view import View +from jenkinsapi.jenkins import Jenkins +J = Jenkins('http://localhost:8080') +print J.items() +j= J['foo'] +j = J.get_job("foo") +b = j.get_last_build() +print b +mjn = b.get_master_job_name() +print(mjn) + +EMPTY_JOB_CONFIG = '''\ + + + + + false + + + true + false + false + false + + false + + + + +''' + +new_job = J.create_job(name='foo_job', config=EMPTY_JOB_CONFIG) \ No newline at end of file diff --git a/examples/how_to/search_artifact_by_regexp.py b/examples/how_to/search_artifact_by_regexp.py new file mode 100644 index 0000000..491e4d2 --- /dev/null +++ b/examples/how_to/search_artifact_by_regexp.py @@ -0,0 +1,8 @@ +from jenkinsapi.api import search_artifact_by_regexp +import re + +jenkinsurl = "http://localhost:8080/jenkins" +jobid = "test1" +artifact_regexp = re.compile("test1\.txt") # A file name I want. +result = search_artifact_by_regexp(jenkinsurl, jobid, artifact_regexp) +print((repr(result))) diff --git a/examples/how_to/search_artifacts.py b/examples/how_to/search_artifacts.py new file mode 100644 index 0000000..5ad7080 --- /dev/null +++ b/examples/how_to/search_artifacts.py @@ -0,0 +1,7 @@ +from jenkinsapi.api import search_artifacts + +jenkinsurl = "http://localhost:8080/jenkins" +jobid = "test1" +artifact_ids = [ "test1.txt", "test2.txt" ] # I need a build that contains all of these +result = search_artifacts(jenkinsurl, jobid, artifact_ids) +print((repr(result )))