How delete views from Jenkins in bulk

Jenkins views can be deleted from the web itself but one at a time. This will be very difficult if the number of views to be removed is higher.

This article explains a Python script that can be used to delete multiple views from Jenkins in one single step.

import jenkins

server = jenkins.Jenkins('URL', username='USER', password='PASS')

views = server.get_views()
view_names = [li['name'] for li in views]

view_exclude = ['VIEW1', 'VIEW2']

for item in view_names:
    if item not in view_exclude:
views = server.get_views()
print (views)

Here URL need to be replaced with the Jenkins url, USER with the Jenkins username and PASS with the Jenkins password.

Please note that we can excude certain views from deletion process. Those names need to be updated instead of VIEW1, VIEW2 etc.

That's all…