build
[!TIP|label:references:]
currentBuild.class== Class RunWrapper
currentBuild.rawBuild.class==jenkins.model.Jenkins.instance.getItemByFullName(String).getBuildByNumber(int).class== Class WorkflowRun
[!TIP|style:flat|label:get builds|icon:fa fa-bullhorn]
inherited from
hudson.model.Job:
WorkflowJob.getBuilds():[marslo/sandbox #2, marslo/sandbox #1]
WorkflowJob.getBuildsAsMap():[2:marslo/sandbox #2, 1:marslo/sandbox #1]
WorkflowJob.getLastFailedBuild(): get last failed build
WorkflowJob.getLastStableBuild(): get last stable build
WorkflowJob.getLastSuccessfulBuild(): get last successful build
WorkflowJob.getLastUnstableBuild(): get last unstalbe build
WorkflowJob.getLastUnsuccessfulBuild(): get last unsuccessful build
WorkflowJob.getLastCompletedBuild(): get last completed only buildfrom
org.jenkinsci.plugins.workflow.job.WorkflowJob:
WorkflowJob.getBuildByNumber(int n): get specific build by number
WorkflowJob.getFirstBuild(): get first build
WorkflowJob.getLastBuild(): get last build
WorkflowJob.getNearestBuild(int n): gets the youngest build #m that satisfies n<=m.
WorkflowJob.getNearestOldBuild(int n): gets the latest build #m that satisfies m<=n.
get build
[!NOTE|label:references:]
get WorkflowRun by build number
get current build actions
result
get build details
result:
get culprits
setup next build number
[!NOTE|label:references:]
build cause
trigger cause
get build cause
result
or
get builds cause within 24 hours
result:
details on Cause.UserIdCause
Cause.UserIdCauseGerritCause
abort cause
builds aborted by timeout
or
abort by userId CauseOfInterruption.UserInterruption
CauseOfInterruption.UserInterruptionget user details
get all abort causes
result:
build log
get console output
check whether if log kept
list build number and start timestamp
or
check last N logs
[!NOTE|label:original log:]
build parameters
result:
or via
action instanceof ParametersActionor by using Job Parameter Summary Plugin
result:
get builds parameters in Jenkinsfile
[!TIP] running following snippet in Jenkinsfile
filter expected parameters and values
[!NOTE|label:reference:]
get wanted parameter values in builds
[!TIP|label:reference:]
result
or simple version
result:
get only String type parameters
String type parametersor
or
[!NOTE|label:refernece:]
build changesets
code clone via DSL
get changeSets to
List<Map<String, String>>:
SCM info
[!TIP]
2 ways to get SCM info
WorkflowRun→WorkflowJob→SCM(currentBuild.rawBuild→getParent()→getDefinition()?.getScm())
WorkflowRun→BuildData(currentBuild.rawBuild→getAction(hudson.plugins.git.util.BuildData))
APIs:
get repo url
result:
build time
[!TIP|label:references]

or:
result:
get started build time
[!NOTE|label:references:] get
lastBuildstart time
sort last build
[!TIP|label:references:]
details:
example:
result:
sort all buildable jobs
list builds
last N builds
list last built N jobs
list last N builds
running builds
[!NOTE|label:references:]
list all running builds via pattern
list builds running more than 24 hours via executor
show
UserIdCause.userId:list job which running for more than 24 hours
[!TIP] only for
lastBuild.
list builds running more than 24 hours via pattern
[!NOTE|label:references:]
scripts:
via job pattern
[!TIP|label:references:]
without table format
get last 24 hours failure builds in Map structure
or
or
via results


with timestamp only
get builds result data range with parameters
[!TIP]
find only
Stringtype parameters:scripts:


get builds result and percentage in data range


get builds result and percentage with params name
stop builds
[!TIP]
stop all queued jobs:
stop all running builds ( in executor ) : * imarslo : force interrupt executors
If your build isn’t aborting
visit : https://<jenkins.domain.com>/threadDump
abort previous running builds by params condition
[!NOTE|label:reference:]
abort running builds if new one is running
or: [cancel builds same job](https://raw.githubusercontent.com/cloudbees/jenkins scripts/master/cancel builds same job.groovy)
[!TIP|label:reference:]
stop all running builds via pattern
[!NOTE|label:references:]
or [cancel builds in same job](https://raw.githubusercontent.com/cloudbees/jenkins scripts/master/cancel builds same job.groovy)
stop all running builds started in 24 hours
[!NOTE|label:references:]
result:
remove builds
[!NOTE|label:references:]
delete multiple builds
setup next build number if necessary
Last updated
Was this helpful?