Create Linked Repository with Bamboo Java Specs

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Purpose

This article will provide an example Java Specs code that can be used to create Linked Repositories

Solution

  • Follow the tutorial Create a simple plan with Bamboo Java Specs to understand how Java specs structure is defined
  • Check the official Bamboo Java specs documentation to get to know how to provide extra options to your Linked repositories
  • Use the following example to create your first Linked Repository via Specs. The provided example will create a Bitbucket type Linked Repository, but you can explore other Repository types such as "pure Git" and SVN

    Currently, Bamboo lacks a feature to export a Linked Repository in Java Specs format. This is being tracked by the following feature request:

    To ease the initial repository code structure in Java Specs format, we advise you to create a temporary Plan repository with the required configuration, export the Plan to Java Specs and use the exported repository definition as a base to create the Linked Repository Specs code. Later on, you can remove the temporary Plan repository.

    package tutorial;
    
    import com.atlassian.bamboo.specs.api.BambooSpec;
    import com.atlassian.bamboo.specs.util.BambooServer;
    import com.atlassian.bamboo.specs.api.builders.applink.ApplicationLink;
    import com.atlassian.bamboo.specs.api.builders.repository.VcsChangeDetection;
    import com.atlassian.bamboo.specs.builders.repository.viewer.BitbucketServerRepositoryViewer;
    import com.atlassian.bamboo.specs.builders.repository.bitbucket.server.BitbucketServerRepository;
    
    @BambooSpec
    public class MyLinkedRepository {
    
        public static void main(String[] args) throws Exception {
            // by default credentials are read from the '.credentials' file
            BambooServer bambooServer = new BambooServer("https://bamboo821.mydomain.net");
    
            final MyLinkedRepository myLinkedRepository = new MyLinkedRepository();
    
            final BitbucketServerRepository repository = myLinkedRepository.repository();
            bambooServer.publish(repository);
        }
    
        public BitbucketServerRepository repository() {
            final BitbucketServerRepository repository = new BitbucketServerRepository()
                .name("Linked Repository BIG")
                .repositoryViewer(new BitbucketServerRepositoryViewer())
                .server(new ApplicationLink()
                    // Add the Application Link name and its id from Bamboo Server
                    .name("Bitbucket")
                    .id("303178d0-29ed-3bd1-90c9-82575f37c8da"))
                // This is the Bitbucket's Project key for the Repository
                .projectKey("BIG")
                .repositorySlug("bigfiles")
                // optional SSH keys
                // .sshPublicKey("ssh-rsa xxx... https://bamboo821.mydomain.net")
                // .sshPrivateKey("BAMSCRT@0@0@5OeUyyy...")
                .sshCloneUrl("ssh://git@bitbucket.mydomain.net:7999/big/bigfiles.git")
                .changeDetection(new VcsChangeDetection());
            return repository;
        }
    }
     
DescriptionCreate Linked Repository with Bamboo Java Specs
ProductBamboo

Last modified on Jan 28, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.