Last updated Dec 8, 2017

Common Bamboo classes

This page outlines some of the more commonly used classes in Bamboo plugins and what sort of information you can retrieve from them

The BuildContext

Every build task contains a BuildContext object. This class encapsulates how to build a particular plan and its state at a given time. You can make sure you have this available to your plugin by either extending the AbstractBuildTask or including the following code

1
2
private BuildContext buildContext;

public void init(@NotNull BuildContext buildContext)
{
    this.buildContext = buildContext;
}

The build context provide you with:

TriggerReason

Interface that encapsulates the reason a build was triggered

BuildPlanDefinition

All information required to execute a particular build plan

BuildChanges

Encapsulates the repository changes for the particular build result

CurrentBuildResult

Subset of the full build result, defines the partial output of a plan being built

BuildPlanDefinition

The BuildPlanDefinition interface encapsulates all information required to execute a particular build plan. The typical case is how to check out given a vcs revision key, then run the builder command and then collect all the various artifacts.

Repository

Used to perform source code related activities

Builder

The builder class knows how to execute your build and determine whether or not the build has passed

Custom Configuration

Any other configuration you want to add to the builds

Artifact Definitions

Which file patterns to copy as artifacts

1
2
buildContext
.getBuildPlanDefinition()
.getArtifactDefinitions()
.add(artifact)

Repository

The RespositoryV2 knows how to deal with your source code. Each type of repository stores its own configuration data required to checkout the source and check for code changes. Bamboo ships with an SvnRepository, CvsRepository and PerforceRepository.

This is where you find information such as

  • Source code directory - Where the source gets checked out to

    1
    2
    buildContext.getRepository().getSourceCodeDirectory(planKey);
    
  • Repository urls

    1
    2
    ((SvnRepository) buildContext.getBuildPlanDefinition().getRepository()).getRepositoryUrl()
    

Current Build Results

The CurrentBuildResults represents the state of the build results throughout the build process. There is variety of information stored in this class, however, different information becomes available at different times throughout the build.

Information you might find here:

  • Build state
  • Build return code
  • Test Results
  • Customer build data
  • Build Errors

Build

The Build represents a Bamboo plan. It contains all the configuration information for the plan, as well as giving you the ability to navigate through the plan's build results. The easiest way to obtain a build is via the BuildManager which can be injected into your plugin.

1
2
Build build = buildManager.getBuildByKey(buildContext.getPlanKey());

Once you have the build you have access to such things as the

  • build definition - contains all the configuration specifics

  • build requirements - set of requirements associated for this build to run

  • parent and child builds

  • build logger

    1
    2
    BuildLogger buildLogger = build.getBuildLogger();
    buildLogger.addBuildLogEntry(...)
    

Build Result

A Build Result is a specific build of a plan e.g BAM-MAIN-567. Currently in Bamboo, build results information is split into two locations. The BuildResultSummary (or ExtendedBuildResultsSummary) is stored in the database and the BuildResult is what is stored as xml in bamboo-home/xml-data/builds/MYBUILDPLAN/results/.

BuildResultSummary

  • Commit Information
  • Trigger Reason
  • Build State
  • Test Counts
  • The agent this build was built on
  • Vcs Revision Key
  • Related Jira Issues
  • Custom Build Data
  • Labels

BuildResult

  • Test results
  • Artifact information

AdministrationConfiguration

The AdministrationConfiguration stores Bamboo's system wide properties such as the default url, instance name, global vairables (as defined in the admin section of Bamboo) and 'System Properties' - which is a map containing any other properties you may want to store for the instance.

You can obtain the administration configuration like so:

1
2
public AdministrationConfiguration getAdministrationConfiguration()
{
    return (AdministrationConfiguration) ContainerManager.getComponent("administrationConfiguration");
}

AdminErrorHandler

The AdminErrorHandler error handler is responsible for dealing with errors that occur while building builds. Currently these errors are displayed on the dashboard of those who have admin privileges.

You can obtain the error handler like so:

1
2
private AdminErrorHandler getAdminErrorHandler()
   {
       if (adminErrorHandler == null)
       {
           adminErrorHandler = (AdminErrorHandler) ContainerManager.getComponent("adminErrorHandler");
       }
       return adminErrorHandler;
   }

Rate this page: