From 19e7f7395aaa0d876a39baf82a80b775d17ff2b3 Mon Sep 17 00:00:00 2001 From: Pascal Hofmann Date: Fri, 20 Dec 2019 17:08:26 +0100 Subject: [PATCH] Include placeholder tasks in get_running_builds Pipeline jobs in in Jenkins 2.x appear as placeholder tasks for their entire lifetime when queried via the API. The fix for #1659787 introduced completly ignoring placeholder tasks. Thus pipeline jobs are never included in the list returned by get_running_builds. This commit will change the behaviour of get_running_builds as follows: - Placeholder tasks will be included: So running pipeline jobs will be included. - Builds which do not have a build number yet will be ignored: This prevents the exception described in #1659787. Change-Id: I30351ec78d6186b0674e3c08be00076b0ce2333e Closes-Bug: #1750372 Related-Bug: #1659787 --- jenkins/__init__.py | 2 +- tests/test_build.py | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/jenkins/__init__.py b/jenkins/__init__.py index 6236f4c..de48f8a 100755 --- a/jenkins/__init__.py +++ b/jenkins/__init__.py @@ -1461,7 +1461,7 @@ class Jenkins(object): raise for executor in info['executors']: executable = executor['currentExecutable'] - if executable and 'PlaceholderTask' not in executable.get('_class', ''): + if executable and 'number' in executable: executor_number = executor['number'] build_number = executable['number'] url = executable['url'] diff --git a/tests/test_build.py b/tests/test_build.py index a4ad4c9..afb36bb 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -432,7 +432,7 @@ class JenkinsListRunningBuildsTest(JenkinsTestBase): @patch.object(jenkins.Jenkins, 'get_node_info') @patch.object(jenkins.Jenkins, 'get_nodes') - def test_placeholder_task_in_queue(self, nodes_mock, node_info_mock): + def test_unnumbered_task_in_queue(self, nodes_mock, node_info_mock): nodes_to_return = [{ 'name': "foo-slave", 'offline': False }] @@ -448,13 +448,7 @@ class JenkinsListRunningBuildsTest(JenkinsTestBase): "progress": -1 }, { - 'currentExecutable': { - '_class': ( - 'org.jenkinsci.plugins.workflow.support.steps.' - 'ExecutorStepExecution$PlaceholderTask$' - 'PlaceholderExecutable' - ) - }, + 'currentExecutable': {}, 'currentWorkUnit': {}, 'idle': False, 'likelyStuck': False,