summaryrefslogtreecommitdiff
path: root/simplejenkinsapi
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-08-11 12:06:00 +0100
committerLars Wirzenius <liw@liw.fi>2012-08-11 12:06:00 +0100
commitc0f00d1200379af420def995092c71d05ba8577c (patch)
tree7efbff06217f35536ff480e39b2c72d84a072ff0 /simplejenkinsapi
parent6112582aa3c64b785b44f791e71483dc677c3cfc (diff)
downloadjenkinstool-c0f00d1200379af420def995092c71d05ba8577c.tar.gz
Move jobconfig.py into new package
Diffstat (limited to 'simplejenkinsapi')
-rw-r--r--simplejenkinsapi/__init__.py1
-rw-r--r--simplejenkinsapi/jobconfig.py89
2 files changed, 90 insertions, 0 deletions
diff --git a/simplejenkinsapi/__init__.py b/simplejenkinsapi/__init__.py
index f16920b..693b180 100644
--- a/simplejenkinsapi/__init__.py
+++ b/simplejenkinsapi/__init__.py
@@ -16,4 +16,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from .jobconfig import JobConfig
diff --git a/simplejenkinsapi/jobconfig.py b/simplejenkinsapi/jobconfig.py
new file mode 100644
index 0000000..1dbf89c
--- /dev/null
+++ b/simplejenkinsapi/jobconfig.py
@@ -0,0 +1,89 @@
+# jobconfig.py -- create Jenkins job config.xml files
+#
+# Copyright 2012 Lars Wirzenius
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+import StringIO
+from xml.etree import ElementTree as ET
+
+
+empty = '''\
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <actions/>
+ <description></description>
+ <keepDependencies>false</keepDependencies>
+ <properties/>
+ <scm/>
+ <canRoam>true</canRoam>
+ <disabled>false</disabled>
+ <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
+ <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
+ <triggers class="vector"/>
+ <concurrentBuild>false</concurrentBuild>
+ <builders/>
+ <publishers/>
+ <buildWrappers/>
+</project>
+'''
+
+
+class JobConfig(object):
+
+ '''Create a Jenkins job configuration XML file.
+
+ This does not try to be complete, and only tries to do the minimal
+ things I need for my automated job creation needs.
+
+ '''
+
+ def __init__(self):
+ self._project = ET.fromstring(empty)
+ self._tree = ET.ElementTree(self._project)
+
+ def tostring(self):
+ f = StringIO.StringIO()
+ self._tree.write(
+ f, xml_declaration=True, method='xml', encoding='UTF-8')
+ return f.getvalue()
+
+ def set_description(self, new_description):
+ description = self._tree.find('description')
+ description.clear()
+ description.text = new_description
+
+ def add_shell_command(self, shell_text):
+ builders = self._project.find('builders')
+ shell = ET.SubElement(builders, 'hudson.tasks.Shell')
+ ET.SubElement(shell, 'command').text = shell_text
+
+ def add_build_trigger(self, job_id):
+ publishers = self._project.find('publishers')
+ trigger = ET.SubElement(publishers, 'hudson.tasks.BuildTrigger')
+ ET.SubElement(trigger, 'childProjects').text = job_id
+ threshold = ET.SubElement(trigger, 'threshold')
+ ET.SubElement(threshold, 'name').text = 'SUCCESS'
+ ET.SubElement(threshold, 'ordinal').text = '0'
+ ET.SubElement(threshold, 'color').text = 'BLUE'
+
+ def set_bzr(self, url):
+ scm = self._project.find('scm')
+ scm.clear()
+ scm.set('class', 'hudson.plugins.bazaar.BazaarSCM')
+ ET.SubElement(scm, 'source').text = url
+ ET.SubElement(scm, 'clean').text = 'false'
+ ET.SubElement(scm, 'checkout').text = 'false'
+