简体   繁体   中英

Jenkins groovy post build action plugin issue

Following code is to find a job in Jenkins and for that job find a required build and addsummary using groovy post build plugin.

def r = jenkins.model.Jenkins.instance.getAllItems().findAll { it.name.contains("<myjob>") }

r.each { t ->
  def builds = t.getBuilds()
  builds.each{ b ->
  if(b.displayName == '<myversion>'){
    manager.createSummary("success.gif").appendText("<h1>Hello!!</h1>", false, false, false, "black")
      }
      b.save()
    }
  }

its failing with following error..

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified method java.lang.Class createSummary java.lang.String
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:113)

You need to go to Jenkins -> Manage Jenkins -> In-process Script Approval .
(From the JENKINS Script Security Plugin )

You will be able to approve that signature there.

See a full example at " Jenkins Groovy Script Approval "

https://cdn-images-1.medium.com/max/1600/1*RQvhikivuJ5526FDNd15lA.png

The Groovy code which you are using should be whitelisted or approved.

It is clear from the error message the code is not approved.

For further information go through this link Script Security Plugin .

Go to Manage Jenkins » In-process Script Approval where a list of scripts pending approval will be shown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM