added a bunch of stuff in a new location
authorSalim Fadhley <sal@stodge.org>
Sun, 16 Jun 2013 23:55:37 +0000 (00:55 +0100)
committerSalim Fadhley <sal@stodge.org>
Sun, 23 Jun 2013 20:21:50 +0000 (21:21 +0100)
examples/how_to/create_views.py [new file with mode: 0644]
examples/how_to/get_config.py [new file with mode: 0644]
examples/how_to/query_a_build.py [new file with mode: 0644]
examples/how_to/search_artifact_by_regexp.py [new file with mode: 0644]
examples/how_to/search_artifacts.py [new file with mode: 0644]

diff --git a/examples/how_to/create_views.py b/examples/how_to/create_views.py
new file mode 100644 (file)
index 0000000..6e8df27
--- /dev/null
@@ -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 (file)
index 0000000..7a10394
--- /dev/null
@@ -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 (file)
index 0000000..c705e6d
--- /dev/null
@@ -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 = '''\
+<?xml version='1.0' encoding='UTF-8'?>
+<project>
+  <actions/>
+  <description></description>
+  <keepDependencies>false</keepDependencies>
+  <properties/>
+  <scm class="hudson.scm.NullSCM"/>
+  <canRoam>true</canRoam>
+  <disabled>false</disabled>
+  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
+  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
+  <triggers class="vector"/>
+  <concurrentBuild>false</concurrentBuild>
+  <builders/>
+  <publishers/>
+  <buildWrappers/>
+</project>
+'''
+
+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 (file)
index 0000000..491e4d2
--- /dev/null
@@ -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 (file)
index 0000000..5ad7080
--- /dev/null
@@ -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 )))