`get_running_builds` raises an error when there are placeholder tasks

Bug #1659787 reported by Graham Lyons
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Jenkins
Fix Released
Undecided
Graham Lyons

Bug Description

The `get_running_builds` method on the `Jenkins` class will raise an exception when it tries to return a list of running builds which contains placeholder tasks.

This line tries to access a build number, which isn't yet available:
https://github.com/openstack/python-jenkins/blob/0f6739103b8b02e3c55ad8d8f4bbb5265273d669/jenkins/__init__.py#L1151

```
>>> j = Jenkins('https://jenkins.example.com', username='jenkins_user', password='password1')
>>> j.get_running_builds()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/jenkins/__init__.py", line 1151, in get_running_builds
    build_number = executable['number']
KeyError: 'number'
```

Changed in python-jenkins:
assignee: nobody → Graham Lyons (grahamlyons)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-jenkins (master)

Fix proposed to branch: master
Review: https://review.openstack.org/431637

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-jenkins (master)

Reviewed: https://review.openstack.org/431637
Committed: https://git.openstack.org/cgit/openstack/python-jenkins/commit/?id=106048dd87478a08e7238c4fe99660137fa30186
Submitter: Jenkins
Branch: master

commit 106048dd87478a08e7238c4fe99660137fa30186
Author: grahamlyons <email address hidden>
Date: Thu Feb 9 16:30:52 2017 +0000

    Fix error thrown in presence of placeholder tasks

    When there are placeholder tasks in an executor for a node then there is no
    build number yet assigned and attempting to access that key in the dictionary
    will fail.

    This fix filters out any tasks which are instances of that class before
    proceeding.

    Change-Id: Ie5b237c3e6023c1822f91e5982ec84f1a363130c
    Closes-Bug: #1659787

Changed in python-jenkins:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-jenkins (master)

Fix proposed to branch: master
Review: https://review.opendev.org/700196

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to python-jenkins (master)

Reviewed: https://review.opendev.org/700196
Committed: https://git.openstack.org/cgit/jjb/python-jenkins/commit/?id=19e7f7395aaa0d876a39baf82a80b775d17ff2b3
Submitter: Zuul
Branch: master

commit 19e7f7395aaa0d876a39baf82a80b775d17ff2b3
Author: Pascal Hofmann <email address hidden>
Date: Fri Dec 20 17:08:26 2019 +0100

    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

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.