Create Linked Repository with Bamboo Java Specs

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Server and Data Center Only. This article only applies to Atlassian products on the server and data center platforms.

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

    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;
        }
    }
     
    • The creation of Linked repositories will only work by publishing it manually instead of using Repository-Stored Specs. We have an open Feature Request for that BAM-20935 - Getting issue details... STATUS

    • The repository definition has to be defined and published separately instead of defining it inside the plan configuration

DescriptionCreate Linked Repository with Bamboo Java Specs
ProductBamboo

Last modified on Jun 28, 2022

Was this helpful?

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