summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalim Fadhley <sal@stodge.org>2014-08-03 01:28:26 +0100
committerSalim Fadhley <sal@stodge.org>2014-08-03 01:28:26 +0100
commitfca182795503b80f89953c9e0ebac9eb602f8e44 (patch)
tree6d4bff9648de521b4ccc8e5dd34e40ea8fc52a1d
parente376b596a768421a502af5a7a85879962800ccc9 (diff)
downloadpython-jenkinsapi-fca182795503b80f89953c9e0ebac9eb602f8e44.tar.gz
python-jenkinsapi-fca182795503b80f89953c9e0ebac9eb602f8e44.tar.bz2
python-jenkinsapi-fca182795503b80f89953c9e0ebac9eb602f8e44.zip
Cut out some more crap, but noticed that invocation of parameterized
builds is broken.
-rw-r--r--examples/how_to/delete_all_the_nodes_except_master.py11
-rw-r--r--jenkinsapi/custom_exceptions.py7
-rw-r--r--jenkinsapi/job.py18
-rw-r--r--jenkinsapi/nodes.py6
-rw-r--r--jenkinsapi/queue.py8
-rw-r--r--jenkinsapi_tests/systests/test_invocation.py10
-rw-r--r--jenkinsapi_tests/systests/test_parameterized_builds.py17
7 files changed, 39 insertions, 38 deletions
diff --git a/examples/how_to/delete_all_the_nodes_except_master.py b/examples/how_to/delete_all_the_nodes_except_master.py
new file mode 100644
index 0000000..e68c89a
--- /dev/null
+++ b/examples/how_to/delete_all_the_nodes_except_master.py
@@ -0,0 +1,11 @@
+import logging
+logging.basicConfig()
+
+from jenkinsapi.jenkins import Jenkins
+
+j = Jenkins('http://localhost:8080')
+
+for node_id, _ in j.get_nodes().iteritems():
+ if not node_id == 'master':
+ print(node_id)
+ j.delete_node(node_id)
diff --git a/jenkinsapi/custom_exceptions.py b/jenkinsapi/custom_exceptions.py
index f3bf286..69009ad 100644
--- a/jenkinsapi/custom_exceptions.py
+++ b/jenkinsapi/custom_exceptions.py
@@ -87,13 +87,6 @@ class TimeOut(JenkinsAPIException):
pass
-class WillNotBuild(JenkinsAPIException):
- """
- Cannot trigger a new build.
- """
- pass
-
-
class NoResults(JenkinsAPIException):
"""
A build did not publish any results.
diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py
index c3b9e9f..f6aabc8 100644
--- a/jenkinsapi/job.py
+++ b/jenkinsapi/job.py
@@ -13,11 +13,9 @@ except ImportError:
import xml.etree.ElementTree as ET
from collections import defaultdict
-from time import sleep
from jenkinsapi.build import Build
from jenkinsapi.queue import QueueItem
from jenkinsapi.jenkinsbase import JenkinsBase
-from jenkinsapi.queue import QueueItem
from jenkinsapi.mutable_jenkins_thing import MutableJenkinsThing
from jenkinsapi.custom_exceptions import (
NoBuildData,
@@ -25,7 +23,6 @@ from jenkinsapi.custom_exceptions import (
NotFound,
NotInQueue,
NotSupportSCM,
- WillNotBuild,
UnknownQueueItem,
)
@@ -166,7 +163,7 @@ class Job(JenkinsBase, MutableJenkinsThing):
file_params)
return json.dumps(to_json_structure)
- def invoke(self, securitytoken=None, block=False, build_params=None, cause=None, files=None):
+ def invoke(self, securitytoken=None, block=False, build_params=None, cause=None, files=None, delay=5):
assert isinstance(block, bool)
# Either copy the params dict or make a new one.
@@ -198,12 +195,13 @@ class Job(JenkinsBase, MutableJenkinsThing):
files=files,
)
- queue_url = response.headers['location']
- qi = QueueItem(queue_url, self.jenkins)
-
- if block:
- qi.block_until_complete(delay=10)
- return qi
+ redirect_url = response.headers['location']
+ if redirect_url.startswith("%s/queue/item" % self.jenkins.baseurl):
+ qi = QueueItem(redirect_url, self.jenkins)
+ if block:
+ qi.block_until_complete(delay=delay)
+ return qi
+ raise ValueError("Not a Queue URL: %s" % redirect_url)
def _buildid_for_type(self, buildtype):
"""Gets a buildid for a given type of build"""
diff --git a/jenkinsapi/nodes.py b/jenkinsapi/nodes.py
index 82fbe70..a3bd036 100644
--- a/jenkinsapi/nodes.py
+++ b/jenkinsapi/nodes.py
@@ -45,11 +45,7 @@ class Nodes(JenkinsBase):
nodeurl = '%s/(%s)' % (self.baseurl, nodename)
else:
nodeurl = '%s/%s' % (self.baseurl, nodename)
- try:
- yield item['displayName'], Node(nodeurl, nodename, self.jenkins)
- except Exception:
- import ipdb
- ipdb.set_trace()
+ yield item['displayName'], Node(nodeurl, nodename, self.jenkins)
def __getitem__(self, nodename):
self_as_dict = dict(self.iteritems())
diff --git a/jenkinsapi/queue.py b/jenkinsapi/queue.py
index 523b4b7..7c04bb5 100644
--- a/jenkinsapi/queue.py
+++ b/jenkinsapi/queue.py
@@ -90,9 +90,13 @@ class QueueItem(JenkinsBase):
JenkinsBase.__init__(self, baseurl)
@property
- def id(self):
+ def queue_id(self):
return self._data['id']
+ @property
+ def name(self):
+ return self._data['task']['name']
+
def get_jenkins_obj(self):
return self.jenkins
@@ -117,7 +121,7 @@ class QueueItem(JenkinsBase):
self.__class__.__name__, str(self))
def __str__(self):
- return "%s Queue #%i" % (self._data['name'], self._data['id'])
+ return "%s Queue #%i" % (self.name, self.queue_id)
def get_build(self):
build_number = self.get_build_number()
diff --git a/jenkinsapi_tests/systests/test_invocation.py b/jenkinsapi_tests/systests/test_invocation.py
index 1d1cbb8..69e03aa 100644
--- a/jenkinsapi_tests/systests/test_invocation.py
+++ b/jenkinsapi_tests/systests/test_invocation.py
@@ -22,7 +22,7 @@ log = logging.getLogger(__name__)
class TestInvocation(BaseSystemTest):
def test_invocation_object(self):
- job_name = 'create_%s' % random_string()
+ job_name = 'Acreate_%s' % random_string()
job = self.jenkins.create_job(job_name, SHORTISH_JOB)
qq = job.invoke()
self.assertIsInstance(qq, QueueItem)
@@ -31,7 +31,7 @@ class TestInvocation(BaseSystemTest):
self.assertEquals(qq.get_build_number(), 1)
def test_get_block_until_build_running(self):
- job_name = 'create_%s' % random_string()
+ job_name = 'Bcreate_%s' % random_string()
job = self.jenkins.create_job(job_name, LONG_RUNNING_JOB)
qq = job.invoke()
time.sleep(3)
@@ -50,14 +50,14 @@ class TestInvocation(BaseSystemTest):
self.assertIn('Started by user', console)
def test_get_block_until_build_complete(self):
- job_name = 'create_%s' % random_string()
+ job_name = 'Ccreate_%s' % random_string()
job = self.jenkins.create_job(job_name, SHORTISH_JOB)
qq = job.invoke()
qq.block_until_complete()
self.assertFalse(qq.get_build().is_running())
def test_multiple_invocations_and_get_last_build(self):
- job_name = 'create_%s' % random_string()
+ job_name = 'Dcreate_%s' % random_string()
job = self.jenkins.create_job(job_name, SHORTISH_JOB)
@@ -72,7 +72,7 @@ class TestInvocation(BaseSystemTest):
self.assertIsInstance(build, Build)
def test_multiple_invocations_and_get_build_number(self):
- job_name = 'create_%s' % random_string()
+ job_name = 'Ecreate_%s' % random_string()
job = self.jenkins.create_job(job_name, EMPTY_JOB)
diff --git a/jenkinsapi_tests/systests/test_parameterized_builds.py b/jenkinsapi_tests/systests/test_parameterized_builds.py
index d13224f..cc25539 100644
--- a/jenkinsapi_tests/systests/test_parameterized_builds.py
+++ b/jenkinsapi_tests/systests/test_parameterized_builds.py
@@ -16,7 +16,6 @@ from jenkinsapi_tests.test_utils.random_strings import random_string
from jenkinsapi_tests.systests.job_configs import JOB_WITH_FILE
from jenkinsapi_tests.systests.job_configs import JOB_WITH_FILE_AND_PARAMS
from jenkinsapi_tests.systests.job_configs import JOB_WITH_PARAMETERS
-from jenkinsapi.custom_exceptions import WillNotBuild
class TestParameterizedBuilds(BaseSystemTest):
@@ -25,11 +24,11 @@ class TestParameterizedBuilds(BaseSystemTest):
file_data = random_string()
param_file = StringIO(file_data)
- job_name = 'create_%s' % random_string()
+ job_name = 'create1_%s' % random_string()
job = self.jenkins.create_job(job_name, JOB_WITH_FILE)
- job.invoke(block=True, files={'file.txt': param_file})
+ item = job.invoke(block=True, files={'file.txt': param_file})
- build = job.get_last_build()
+ build = job.poll().get_last_build()
while build.is_running():
time.sleep(0.25)
@@ -40,20 +39,20 @@ class TestParameterizedBuilds(BaseSystemTest):
# def test_invoke_job_parameterized(self):
# param_B = random_string()
-#
-# job_name = 'create_%s' % random_string()
+#
+# job_name = 'create2_%s' % random_string()
# job = self.jenkins.create_job(job_name, JOB_WITH_PARAMETERS)
# job.invoke(block=True, build_params={'B': param_B})
-#
+#
# build = job.get_last_build()
# while build.is_running():
# time.sleep(0.25)
-#
+#
# artifacts = build.get_artifact_dict()
# self.assertIsInstance(artifacts, dict)
# artB = artifacts['b.txt']
# self.assertTrue(artB.get_data().strip(), param_B)
-#
+#
# self.assertIn(param_B, build.get_console())
#
# def test_parameterized_job_build_queuing(self):