Does a programmatic method exist to create Linked Repositories?
Asked by Chad Benn:

I'm leveraging all of the goodness of Spec Plans, but it depends heavily on an existing Linked Repository.

Here is what I have so far:

**Step 1** - Use the Bitbucket API to setup a code repository \[++scripted++\]

**Step 2** - Log into Bitbucket, create 'Linked Repository' (LR) to new code repo \[++manual++\]

**Step 3** - Execute java Spec Plan to create a Bamboo Build Plan (linked to the LR) \[++scripted++\]

You can see the significant interrupt in my attempt to create a push-button setup.

The closest I find is Bob Swift's CLI tool. While neat, I don't have local Bamboo Admin access.

All actions must be via API or remotely.

Thanks in advance!


Answers:
author: Alexey Chystoprudov
body: Try Bamboo Specs for linked repositories management

```
BambooServer bambooServer = new BambooServer("http://localhost:6990/bamboo");
final GitRepository gitRepository = new GitRepository()
        .name("Test repository")
        .url("https://bitbucket.org/user/test.git")
        .branch("master")
        .authentication(new UserPasswordAuthentication("user")
                .password("password"))
        .changeDetection(new VcsChangeDetection());
bambooServer.publish(gitRepository);
```

comments: author: Chad Benn
body: Thanks Alexey, but a recent article indicates that global linked repository are preferred and that manually configured repository are to be deprecated. So I was hoping to adopt the preferred method.

Article - <https://confluence.atlassian.com/bamboo/linking-to-source-code-repositories-671089223.html>


author: Alexey Chystoprudov
body: This code creates global linked repository


author: Hema
body: Hi [@Alexey Chystoprudov](/t5/user/viewprofilepage/user-id/781646)

Will above code create linked repository and how to enable scan for bamboo specs in this code. I want to create linked repository with scan bamboo specs in bitbucket. So can I do it in java.


author: Alexey Chystoprudov
body: [@Hema](/t5/user/viewprofilepage/user-id/3179637) , it will create repository. Then you need to enable Specs detection <https://docs.atlassian.com/atlassian-bamboo/REST/6.9.0/#d2e4449>

```
curl -u admin:admin -X PUT http://localhost:8085/rest/api/latest/repository/123/enableCi
```

Then you also need to grant permissions to particular projects or grant access for this repo to [all your projects](https://docs.atlassian.com/atlassian-bamboo/REST/6.9.0/#d2e4482).

Unfortunately there's no Rest API to get repo id by its name so you need to get it manually through UI. You can watch and vote for <https://jira.atlassian.com/browse/BAM-20007> to address it.


author: Hema
body: Hi [@Alexey Chystoprudov](/t5/user/viewprofilepage/user-id/781646) ,

Thanks for response.

I created plan using bitbucket spec repository but when I saw bamboo plan, it is not allowing to edit on bamboo. Showing message like edit this plan using bitbucket spec repository. So can you please help me if I want to create plan using butbucket repo as well modify changes using bamboo UI.

Also how to enable scan for bamboo spec using bamboo java spec


author: Alexey Chystoprudov
body: Once plan is managed by repository you can't edit it by UI. If you need to turn it off - publish it from local environment by command executed at bamboo-specs folder of your repo.

mvn -Ppublish-specs

It's not possible to enable Bamboo Specs property of repository from Bamboo Specs


author: Hema
body: Thank you, [@Alexey Chystoprudov](/t5/user/viewprofilepage/user-id/781646)


author: Hema
body: Hi [@Alexey Chystoprudov](/t5/user/viewprofilepage/user-id/781646)

I have created bamboo spec stored in bitbucket repository and created lonked repository in bamboo, enabled scan for spec. But when bamboo scan for spec, it is asking for ssh private and public key for plan repository stored in bitbucket RSS. If I mentioned public and private key then it publish plan repository in plan. So if any other user change in spec then will it work for him.

What exactly consists in public and private key ie is it specific to user


author: Jeyanthan I
body: Hi Chad,

Bamboo does not provide the REST end point to create a new linked repository (yet as of Bamboo 6.4.1). I found an open feature request for this - [BAM-18453](https://jira.atlassian.com/browse/BAM-18453)

I recommend you vote for it and comment to get it prioritised.


Tags: bitbucket

link

repository