Jenkins currentBuild

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

currentBuild is a global variable that may be used to refer to the currently running build. It has the following properties and methods.

Properties

number

The build number, which is an integer.

result

https://javadoc.jenkins-ci.org/hudson/model/Result.html

Typically "SUCCESS", "UNSTABLE", "FAILURE", "NOT_BUILT", "ABORTED". May be null for an ongoing build. The property is writable:

currentBuild.result = 'FAILURE'

Also see:

Scripted Pipeline Failure Handling
Pipeline Result

currentResult

Typically "SUCCESS", "UNSTABLE" or "FAILURE". Is never null. If no failure occurred, the result is "SUCCESS".

Also see:

Scripted Pipeline Failure Handling

displayName

Normally "#<number>". The property is writable.

fullDisplayName

Normally folder1 > folder2 > something #123.

projectName

Name of the project (pipeline) of this build.

fullProjectName

Full name of the project of this build, including folders such as folder1/folder2/something.

description

Additional information about the build. The property is writable.

id

Normally the build number as a string.

timeInMillis

Time since the epoch when the build was scheduled.

startTimeInMillis

Time since the epoch when the build started running.

duration

Duration of the build in milliseconds.

durationString

A human-readable representation of the build duration.

previousBuild

Previous build of the project, or null.

previousBuildInProgress

Previous build of the project that is currently building, or null.

previousBuiltBuild

Previous build of the project that has been built (may be currently building), or null.

previousCompletedBuild

Previous build of the project that has last finished building, or null.

previousFailedBuild

Previous build of the project that has last failed to build, or null.

previousNotFailedBuild

Previous build of the project that did not fail to build (eg. result is successful or unstable), or null.

previousSuccessfulBuild

Previous build of the project that has successfully built, or null.

nextBuild

Next build of the project, or null.

absoluteUrl

URL of build index page.

buildVariables

For a non-Pipeline downstream build, offers access to a map of defined build variables. For a Pipeline downstream build, any variables set globally on env at the time the build ends. Child Pipeline jobs can use this to report additional information to the parent job by setting variables in env. Note that build parameters are not shown in buildVariables.

changeSets

upstreamBuilds

rawBuild

keepLog

True if the log file for this build should be kept and not deleted. The property is writable.

Methods

resultIsBetterOrEqualTo(String)

Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is better than or equal to the provided result.

resultIsWorseOrEqualTo(String)

Compares the current build result to the provided result string (SUCCESS, UNSTABLE, or FAILURE) and returns true if the current build result is worse than or equal to the provided result.