Few things, I started to see these exceptions after I added usage of this function before every state:
def isNodeActive()
{
try
{
def nodes = jenkins.model.Jenkins.getInstance().getNodes();
def nodeName = "${NODE_NAME}";
for(Slave node in nodes)
{
if (node.getNodeName() != nodeName)
{
continue;
}
if (node.getComputer().isAcceptingTasks())
{
return true;
}
}
}
catch (Exception e) {
return false;
}
return false;
}
I running most of tests in single jobs mainly during night on 40+ servers. And wanted to stop starting new tests when servers run offline due to schedule. – I also have separate jobs that run this code, to kill these hanging jobs (that hang on node allocation).
import hudson.model.FreeStyleBuild
import hudson.model.Job
import hudson.model.Result
import hudson.model.Run
import java.util.Calendar
import jenkins.model.Jenkins
import org.jenkinsci.plugins.workflow.job.WorkflowRun
import org.jenkinsci.plugins.workflow.support.steps.StageStepExecution
//24 hours in a day, 3600 seconds in 1 hour, 1000 milliseconds in 1 second
long time_in_millis = 24*3600*1000
Calendar rightNow = Calendar.getInstance()
for(Job job in Jenkins.instance.getAllItems(Job.class))
{
if (!job.isBuilding())
{
continue;
}
for(Run item in job.builds)
{
if (!item.isBuilding())
{
continue;
}
if ((rightNow.getTimeInMillis() - item.getStartTimeInMillis()) < time_in_millis)
{
continue;
}
if(item in WorkflowRun) {
WorkflowRun run = (WorkflowRun) item
//hard kill
run.doKill()
//release pipeline concurrency locks
StageStepExecution.exit(run)
println "Killed ${run}"
} else if(item in FreeStyleBuild) {
FreeStyleBuild run = (FreeStyleBuild) item
run.executor.interrupt(Result.ABORTED)
println "Killed ${run}"
} else {
println "WARNING: Don't know how to handle ${item.class}"
}
}
}
– But above function shouldn't be executed in this case:
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/checkCommit@46
[Pipeline] End of Pipeline
java.lang.ArrayIndexOutOfBoundsException
Finished: FAILURE
Above "node" is allocated in try - finally block, but looks like finally block where not executed. And then job hangs (still taking place in node - could be above script issue). |