Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

What is the proper way to access a build artifact from within a bamboo 3.x plugin?

Drew NICHOLS December 20, 2011

I'm building a bamboo 3.3 plugin and would like to access an artifact of my build. I've been able to successfully see the ArtifactDefinitionContext using buildContext.getArtifactContext().getDefinitionContexts() however there doesn't seem to be a convenient way to grab a file from a bulds's artifacts.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 20, 2011
Have a look at com.atlassian.bamboo.build.artifact.ArtifactManager#retrieve .
Drew NICHOLS December 20, 2011

That method offers the following signature and it's unclear how to access files within a builds artifacts.

public boolean retrieve(PlanResultKey planResultKey, ArtifactSubscriptionContext artifactSubscription, java.io.File buildWorkingDirectory)

Specifically what I'd like to do is read the clover.xml file generated on a successful build.

Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 20, 2011

That's because it's really meant to be used by plans other than the one that created the artifact. In your case, it's tricky because using it requires subscription context available in subscribing jobs, but not publishing jobs.

In your case, it will be simpler to access the file directly, e.g. com.atlassian.bamboo.fileserver.SystemDirectory#getArtifactDestinationDirectory

Drew NICHOLS December 20, 2011

Good news is that the following worked. Worked in that it's able to find the build's artifacts.

for (ArtifactDefinitionContext artifact : buildContext.getArtifactContext().getDefinitionContexts())
    {
      if(StringUtils.equals("Clover Report (System)", artifact.getName()))
      {
        
        File destinationDir = SystemDirectory.getArtifactDestinationDirectory(buildContext.getPlanResultKey(), artifact);
        
        File cloverXml = new File(destinationDir.getAbsolutePath() + destinationDir.separator + "site/clover/clover.xml");
        
        logger.info(cloverXml.getAbsoluteFile() + " exists=" + cloverXml.exists());
      }
      
    }

Unfortunately I incorrectly assumted that the clover.xml file was captured as part of the report. It appears that by default the clover.xml file is left in the working directory.

What's the best way to get access to the builds's working directory?

Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 20, 2011

Are you running the plugin on agent side or server side? Is the clover.xml defined as a shared artifact or a regular artifact?

Drew NICHOLS December 20, 2011

It can run agent side. I know that's required to access the working directory.

the clover.xml is not defined as a shared artifact. There is just an artifact which the clover plugin auto defines as follows:

Name: Clover Report (System)

Location: target/site/clover

Copy Pattern: **/*.*

Przemek Bruski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 20, 2011

If it runs on agent side, you don't have to worry about ArtifactManager or the Artifact directory - since you were talking about artifacts, I assumed you meant server side. For a Job that creates artifacts, the artifact really start to exist on the server side.

In your case, you should just access the file directly in the build working directory. Try com.atlassian.bamboo.v2.build.BuildContextHelper#getBuildWorkingDirectory .

It may be an overkill in your case, but to get the same list of files that Bamboo uses to find the file, instantiate FileSet (have a look at com.atlassian.bamboo.build.artifact.AbstractArtifactManager#createFileSet) and do something like:

final DirectoryScanner directoryScanner = sourceFileSet.getDirectoryScanner();
        directoryScanner.scan();
        for (final String fileName : directoryScanner.getIncludedFiles()) {}

Drew NICHOLS December 20, 2011

Thanks for the help. I used the following and it worked fine:

File workingDirectory = BuildContextHelper.getBuildWorkingDirectory(buildContext);
    
    File cloverXml = new File(workingDirectory.getAbsolutePath() + File.separator + pathToColverFile);

0 votes
gopikrsihan gadu February 16, 2012

Hi

I configured one-click clover integration on bamboo plan but no reports are generating.

Could someone suggest the correct pattern for clover artifact configuration. also please tell me possible reason for below error.

Failed to execute plugin 'Clover Results Collector' with error: No file matches the specified pattern:target/site/clover/**/clover.xml

Thanks

Gopi

0 votes
Tam Nguyen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2011

You can see the implementating classes AbstractArtifactManager, LocalArtifactManager, RemoteArtifactManager

TAGS
AUG Leaders

Atlassian Community Events