jenkinsgroovyjenkins-pluginsjenkins-groovy

How to use `StaplerResponse rsp` in `AsyncResourceDisposer.doStopTracking()`


I'm trying to remove (stop tracking) trackig item from Jenkins AsyncResourceDisposer (${JENKINS_URL}/administrativeMonitor/AsyncResourceDisposer) via groovy scripts (${JENKINS_URL}/script).

According to the Javadoc and source code

// Javadoc
@Restricted(value=org.kohsuke.accmod.restrictions.DoNotUse.class)
public org.kohsuke.stapler.HttpResponse doStopTracking(@QueryParameter
  int id,
  org.kohsuke.stapler.StaplerResponse rsp
)

// source code
@Restricted(DoNotUse.class)
@RequirePOST
public HttpResponse doStopTracking(@QueryParameter int id, StaplerResponse rsp) {
...
}

I'd like to know how to add org.kohsuke.stapler.StaplerResponse rsp in doStopTracking(int id, org.kohsuke.stapler.StaplerResponse rsp):

import org.jenkinsci.plugins.resourcedisposer.AsyncResourceDisposer

AsyncResourceDisposer disposer = AsyncResourceDisposer.get()
disposer.backlog.each {
  disposer.doStopTracking( it.id, <what should I put here> )
}

Current I can get the item id, and the other informaitons like below:

import org.jenkinsci.plugins.resourcedisposer.AsyncResourceDisposer

AsyncResourceDisposer disposer = AsyncResourceDisposer.get()
String url = Jenkins.instance.rootUrl + disposer.url

disposer.getBacklog().each { item ->
  println "\n${item.id} : \t${url}/stopTracking/?id=${item.id} : \t${item.class.simpleName} : \n" +
          "\t${item.getLastState().getDisplayName()} : \n" + 
          "\t${item.getDisposable().node} : ${item.getDisposable().path}\n" +
          "\t${item.toString()}"
}

If I'm go to the url "${url}/stopTracking/?id=${item.id}" in browser (login first), the item can be removed after click RETRY USING POST (as below) enter image description here


Solution

  • Had the same issue to clean the memory-consuming resources stuck there. Here is the solution to clean all from groovy:

    import org.jenkinsci.plugins.resourcedisposer.AsyncResourceDisposer
    import org.kohsuke.stapler.StaplerResponse;
    import org.kohsuke.stapler.Stapler
    
    AsyncResourceDisposer disposer = AsyncResourceDisposer.get()
    backlog = disposer.getBacklog()
    
    stap = Stapler
    resp = stap.getCurrentResponse()
    
    for (item in disposer.backlog) {
      disposer.doStopTracking( item.id, resp )
    }