Setup - Latest Jenkins with pipeline job set to run from MultiBranch
Pipeline (bitbucket)
Library Function - Its replacing the block plugin where you can specify
when this job should wait for other jobs running on a node
I havent seen issues with other functions but I am unable to get NodeName
for jobs running through MultiBranch pipelines.
def call(pattern)
{
def mJInstance = Jenkins.getActiveInstance()
def mJenInstance = mExternalConst.getJenkinsInst()
def mJenJobs = mJenInstance.getAllItems()
def mJenJobsSize = mJenJobs.size()
def mResult = [] as Set
def mBoolAnswer = false
def mJobPattern = pattern;
if (pattern?.trim())
{
println "\nTotal jobs running on Jenkins - [Size $mJenJobsSize
]\nList of Jobs with pattern [ $mJobPattern ] "
if (mJenJobsSize > 0)
{
def running
def build
for (i = 0; i < mJenJobsSize; i++)
//mJenJobs.each
{
def locJob = mJenJobs[i]
if (locJob.getDisplayName() =~ mJobPattern)
{
if (locJob.lastBuild != null)
{
if (!(locJob.getDisplayName() =~ env.JOB_BASE_NAME
)) //Skip the job itself
{
running = locJob.getLastBuild().isBuilding()
if (running)
{
build = locJob.getLastBuild()
println "\t" + 'JOB: ' + "[NAME " +
locJob.getName() + " - " + locJob.getClass() + "] " +
//"\n\t[InProgress " + build.isInProgress()
+ "] " +
"\n\t[Node " +
locJob.getLastBuiltOn().getNodeName() + "] " + // ************
LINE WITH ISSUE ***********
"\n\t[Node " +
build.getExecutor().getOwner().getName() + "] " + // ************
LINE WITH ISSUE ***********
"\n\t[Build# " + build.getNumber() + "] " +
"\n\t[EstTimeRemain " +
build.getExecutor().getEstimatedRemainingTime() + "] " +
"\n\t[Progress " +
build.getExecutor().getProgress() + "/100] "
mResult.add(locJob.getName())
}
}
}
}
}
} else
println "\tNo jobs on this Jenkins box"
mResultSize = mResult.size()
if (mResultSize > 0)
{
println "\nFound [ $mResultSize ] jobs matching [ $pattern ] on
this Jenkins"
mBoolAnswer = true
} else
println "\nNo jobs found matching [ $pattern ] on this Jenkins"
} else
println "Please provide a pattern to this function. e.g\n
jobRunning('OdinPlugin.*-')"
return mBoolAnswer
}
Here's the output I am getting :
---------------------
*15:28:39* JOB: [NAME First-Test - class
org.jenkinsci.plugins.workflow.job.WorkflowJob]
*15:28:39* [Node ]
*15:28:39* [Node ]
*15:28:39* [Build# 191]
*15:28:39* [EstTimeRemain N/A]
*15:28:39* [Progress 99/100]
---------------------
You can see here the Node name is not getting printed, one reason I can see
for Option2 [build.getExecutor().getOwner().getName()] was its class
[hudson.model.Hudson$MasterComputer]
which has empty nodeName.
Does anyone know how to get nodeName for a MultiBranchPipeline job, the
same thing works for older style FreeFlowJobs
--
You received this message because you are subscribed to the Google Groups
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-users/53ed3df7-a767-476c-a748-1b701100a780%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.