I'm trying to delete a Jenkins view programmatically but my Jenkins job:
import jenkins.model.*;
import jenkins.util.*;
jenkins = Jenkins.instance
def view = jenkins.getView("my-view")
jenkins.deleteView( view )
fails giving:
[workspace] $ groovy /var/lib/jenkins/jobs/DeleteViews/workspace/hudson8664703220024294601.groovy
Caught: groovy.lang.MissingPropertyException: No such property: Jenkins for class: hudson8664703220024294601
groovy.lang.MissingPropertyException: No such property: Jenkins for class: hudson8664703220024294601
at hudson8664703220024294601.run(hudson8664703220024294601.groovy:4)
Build step 'Execute Groovy script' marked build as failure
I've seen solutions like this:
https://stackoverflow.com/a/42020732/343204
and suggestions on how to import like this:
Running Groovy command from Jenkins using Groovy script plugin
but not sure how to proceed.
Any suggestions?