New workspace created

Jenkins version 2.377

Hi all,

After aborting a pipeline we now have a new workspace directory opt/jenkins/workspace/some-project@2

While it doesn’t break subsequent builds it causes issues with our CI Observability tool.

Is there a way to reset the path? I tried removing the workspace from the worker but it keeps coming back with @2.

I’d appreciate some help with that.

One solution is delete the agent where this happened from Jenkins and then recreate the agent. Restarting Jenkins should also resolve the problem.

Sometime ago I’ve seen this happen more often so I have written a small freestyle job that allows me to remove such workspaces.
So you will need to create a freestyle job with 3 parameters

  • agentName (String)
  • ws (String) the full path to the workspace
  • dryrun (Boolean)

Then paste below script in a Execute System Groovy script and run the job.

import jenkins.model.Jenkins
import hudson.console.HyperlinkNote

j = Jenkins.get()

final def resolver = build.buildVariableResolver

agentName = resolver.resolve("agentName").trim()
ws = resolver.resolve("ws")

P_DRYRUN = resolver.resolve("dryrun")
dryrun = "true".equals(P_DRYRUN)

nodeLink = HyperlinkNote.encodeTo("/computer/" + agentName, agentName)

println(nodeLink)
println("Dryrun: " + dryrun)

agent = j.getNode(agentName)
if (agent == null)
{
  println("Agent not found: " + agentName)
  return 1
}
c = agent.toComputer()


busyExecutors = c.countBusy()
	executorCount = c.countExecutors()
    workspaceCount = c.workspaceList.inUse.keySet().size()
    println("  Busy  Executors: " + busyExecutors )
    println("  Workspaces     : " + workspaceCount)
    println("  Executor count : " + executorCount)

	for (e in c.getExecutors())
	{
      if (e.isBusy()) 
      {
      }
    }
    for (entry in c.workspaceList.inUse.entrySet())
    {
      key = entry.getKey()
      value = entry.getValue()
      println("    " + key)
      println("    " + value)
      println("    " + value.context.getClass().getName())
      if (key ==~ /.*@\d+$/ )
      {
        println("  Error: Found an workspace with count > 1")
      }
    }
    if (workspaceCount > busyExecutors)
    {
      println("  Error:  Found an active workspace although no executors are busy")
    }

if (!dryrun)
{
  println("  Removing inUse workspace " + ws)
  result = c.workspaceList.inUse.remove(ws)
  if (result == null) {
    println(ws + " was not included in the workspace list")
    return 1
  }
}


return
1 Like

Thanks @mawinter69. Removing and recreating the agent worked.