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 build

  • from 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

GerritCause

abort cause

builds aborted by timeout

  • or

abort by userId CauseOfInterruption.UserInterruption

  • get 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

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

  • or

  • 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

references:

  • result:

build time

more details can be found in

[!TIP|label:references]

get build start time
  • or:

  • result:

get started build time

[!NOTE|label:references:] get lastBuild start time

sort last build

[!TIP|label:references:]

  • 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

list builds running more than 24 hours via pattern

[!NOTE|label:references:]

via job pattern

[!TIP|label:references:]

  • without table format

get last 24 hours failure builds in Map structure

  • or

  • or

via results

build status

build status for jobs within 24 hours
  • with timestamp only

get builds result data range with parameters

[!TIP]

filter build history via params
filter build history via params details

get builds result and percentage in data range

build-history-with-status-and-percentage-for-params
build-history-with-status-and-percentage-for-all-builds

get builds result and percentage with params name

stop builds

[!TIP]

abort previous running builds by params condition

[!NOTE|label:reference:]

[!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?