0

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?

Snowcrash
  • 80,579
  • 89
  • 266
  • 376

1 Answers1

0

As I understand, you use freestyle job with step "Execute Groovy script". So, you need to change this step to "Execute system Groovy script" and your code will work.

Mikhail Naletov
  • 285
  • 1
  • 2
  • 12