12

I want to delete Views under Jenkins without affecting the Jobs under the view. I am asking this since I am not able to enter same name of View even after deleting this as an Administrator.

I checked Config file under Jenkins folder and tried editing the View name but that didn't work.

I need a confirmation whether below script will delete the View name only or along with Jobs under view.

BE AWARE the following scriptlet deletes all your jobs!!!

Jenkins.instance.getView("MyView").items.each { item ->
    println "deleting $item.name"
    item.delete()
}

enter image description here

Jeroen Steenbeeke
  • 3,884
  • 5
  • 17
  • 26
asur
  • 1,759
  • 7
  • 38
  • 81

2 Answers2

30

go to view --> edit view --> unchecked all jobs on that view --> Save --> Delete View

Avinash
  • 2,093
  • 4
  • 28
  • 41
  • I didnt find any option of " unchecked all jobs on that view --> Save --> Delete View." Added the screenshot. Jenkins Version - 1.652 – asur Feb 03 '17 at 09:14
  • 1
    This is not any option, this is what you have to `un-check` jobs which are checked under that view. – Avinash Feb 03 '17 at 09:17
  • 1
    Ahh your jenkins version is pretty old 1.652, you can go by DSL using jenkins.instance.deleteView() Check the behavior in jenkins_url/script – Avinash Feb 03 '17 at 09:27
  • If your view is 'Default View' then first un-select that view as default, then and then only you can delete view. – Bhushan Jan 17 '19 at 04:37
  • 1
    @Kally it's maybe because you created `My View` instead `List View`. – Сергей Feb 17 '20 at 09:49
6

For deleting a view (and not touching any jobs therein) use

def view = Jenkins.instance.getView("MyView")
Jenkins.instance.deleteView( view )

Your code deletes the jobs in the view (but not the view itself), so be careful with that : )

Alex O
  • 7,746
  • 2
  • 25
  • 38