install_plugin api throwing array index out of bound exception

Bug #1806381 reported by rohan
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Python Jenkins
In Progress
Undecided
Kazuhiro Suzuki

Bug Description

I am using python jenkins api for automation purpose.
following is sample code snippet.
server=jenkins.Jenkins('http://127.0.0.1', username='admin', password='admin')

server.install_plugin("windows-slaves")

error-

response = response_str.split(':')[1].strip().lower() == 'true'
IndexError: list index out of range

the response_str is actually ')]}'.

rohan (rvadje)
Changed in python-jenkins:
assignee: nobody → rohan (rvadje)
rohan (rvadje)
information type: Public → Public Security
rohan (rvadje)
information type: Public Security → Public
Revision history for this message
Dan Nicholson (danbnicholson) wrote :

I'm not sure how this ever worked, but the issue is that the code expects that Jenkins will return a string like "Result: <bool>" where the boolean is the result of the call to check whether a restart is needed. However, the Groovy script run for this neither gathers the result or prints it in the format expected. I guess maybe old versions of Jenkins took a boolean result of the script itself and printed "Result: <script result>".

The following patch seems to work for me:

--- __init__.py.orig 2019-04-04 10:13:50.728569000 -0500
+++ __init__.py 2019-04-10 17:12:28.505247839 -0500
@@ -1347,8 +1347,9 @@
         # run_script is an async call to run groovy. we need to wait a little
         # before we can get a reliable response on whether a restart is needed
         time.sleep(2)
- is_restart_required = ('Jenkins.instance.updateCenter'
- '.isRestartRequiredForCompletion()')
+ is_restart_required = ('boolean reboot = Jenkins.instance.updateCenter'
+ '.isRestartRequiredForCompletion();'
+ 'println "Result: ${reboot}"')

         # response is a string (i.e. u'Result: true\n'), return a bool instead
         response_str = self.run_script(is_restart_required)

However, since we're managing the returned string ourselves, it might be better to use JSON or something.

Revision history for this message
DeVonte Applewhite (dapplewh) wrote :

Hello, will the fix proposed by Dan Nicholson be added to a release some time soon? I verified that it worked. I am trying to automate plugin updates and this library is making it possible to do so.

Revision history for this message
Ramesh (rameshpasham) wrote :

Hello Rohan, In which release, will it be included ?

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/719059

Changed in python-jenkins:
assignee: rohan (rvadje) → Kazuhiro Suzuki (ksauzz)
status: New → In Progress
Revision history for this message
Lingfei Ouyang (oylf1985) wrote :

Hello Rohan, quick follow up with this bug, when will this fix been released?

Revision history for this message
Kazuhiro Suzuki (ksauzz) wrote :

I already submitted the fixes, but no reaction from any maintainer. Additionally CI partially didn't work at the time. I'm not sure how to proceed after the maintainer fixed CI.

If anyone needs a quickfix, you can try my fork. (https://github.com/ksauzz/python-jenkins)

How to use:

pip install git+https://github.com/ksauzz/python-jenkins.git@0.0.1#egg=python-jenkins

Fixes:
- https://review.opendev.org/#/c/719058/2
- https://review.opendev.org/#/c/719059/2

Revision history for this message
Danny (danny-smit-0) wrote :

Ran into the issue as well. Merging the fix would be nice, as it seems to work. What needs to be done to finish it?

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.