Bamboo yaml spec, create plan repositories
Asked by sasank nvs:

Hi there,

I followed the documentation of Bamboo Yaml specs to create plan repositories as below.

repositories:  
- my-test:  
type: bitbucket-server  
server: <http://localhost:7990>  
project: TestProject  
slug: test-service  
clone-url: ssh://git@scr.bsh-sdd.com:7990/testproject/test-service.git  
public-key: PUBLIC KEY  
private-key: ENCRYPTED_PRIVATE_KEY

I provided the actual public key and private key in the yaml and the pulic key is configured in the bit bucket server to my account. **When tried like this I am the error.**

```
Cannot read keypair, passphrase wasn't set
```

**But I am not sure how I should provide the passphrase.**

**And when I remove public-key and private-key fields I get below error.**

```
Bamboo YAML import failed: Repository 'my-test' should be defined at 'repositories' list when referenced by Checkout task
```

Can someone help me here ?


Answers:
author: Eduardo Alvarenga
body: Hello [@sasank nvs](/t5/user/viewprofilepage/user-id/4856811), Welcome to **Atlassian Community**!

To use an SSH private key with a passphrase, you should set the repository type as "git" and on your YAML file:

```
ssh-key: <Encryptedkey>
ssh-key-passphrase: <EncryptedPassphrase>
```

To generate an encrypted string to Specs -\> Bamboo Specs Encryption (located on the top menu bar in Bamboo)

When using a *Bitbucket-server* repository type, Bamboo takes over SSH key management and won't allow personal keys to be used, nor passphrases.

Regards,

Eduardo Alvarenga  
Atlassian Support APAC

comments: author: sasank nvs
body: Thanks [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410) for such a prompt reply. I was able to get it worked with git. But not able to get it working with Bitbucket. I tried below configuration but still I got the error. Also I don't have any access token configured on the Bitbucket repository.

- my-test:  
type: bitbucket-server  
server: Bitbucket  
project: testproject  
slug: test-service  
clone-url: ssh://git@scr.bsh-sdd.com:7990/testproject/test-service.git

```
Bamboo YAML import failed: Repository 'my-test' should be defined at 'repositories' list when referenced by Checkout task
```

I got the above error.


author: Eduardo Alvarenga
body: You are missing a repository declaration. Try this:

```
Default Job:
key: JOB1
tasks:
  - checkout:
repository: my-test
force-clean-build: 'false'
description: Checkout My-test

repositories:
  - my-test:
      type: bitbucket-server
      server: Bitbucket
      project: testproject
      slug: test-service
      clone-url: ssh://git@scr.bsh-sdd.com:7990/testproject/test-service.git
```


author: Dimitri Dering
body: Hello Eduardo,

I work together with Sasank on this issue and just figured out the solution

- The provided SSH key pair must be RSA keys (not OpenSSH)  
- The public key is plain, the private key must be Bamboo encrypted  
- The property viewer with the following value is required (otherwise an error message saying that changing the repo type is not allowed is thrown)  
viewer: *com.atlassian.bamboo.plugins.stash.atlassian-bamboo-plugin-stash:bbServerViewer*   
- I also added the public key to the bitbucket repo keys (in bitbucket project settings)

The final piece of repo config in the bamboo YAML spec looks like the following

```
repositories:
  - my-test:
      type: bitbucket-server
      server: <bit bucket app link name>
      project: <project-key>
      slug: <repo-slug>
      clone-url: <ssh-git-repo>
      public-key: <public-key>
      private-key: <private-key>
      branch: master
      viewer: com.atlassian.bamboo.plugins.stash.atlassian-bamboo-plugin-stash:bbServerViewer

```

<br />

As far as I have seen, all properties here are mandatory.  

We would also like to specify the "**Change detection part** ", especially to include only changes that matches a specific RegEx.  

Unfortunately I couldn't find this part in the YAML specs reference, do you have hint for us?


author: Eduardo Alvarenga
body: Hey [@Dimitri Dering](/t5/user/viewprofilepage/user-id/4853938) [@sasank nvs](/t5/user/viewprofilepage/user-id/4856811)

I noticed the similarity between your work questions but didn't want to assume you teamed. But now that everything is clear, that makes things easier to understand.

Regarding the **Change detection** options, you can try adding something like this:

```
repositories:
  - my-test:
      (...)
      change-detection:
      file-filter-type: include_only
      file-filter-pattern: ^(string1|string2)/.*
```

Modify the file-filter-pattern [regex](http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html) to what suits you.

**Pro-tip**. You can always use the Bamboo UI to export the Plan in either YAML or Java Specs format. For that, simply prepare your plan, then go to:

* Actions -\> Configure Plan -\> Actions -\> View Plan as (Java/YAML) Specs


author: Dimitri Dering
body: perfect, this solved our issue completely  

thank you very much


author: Eduardo Alvarenga
body: Thanks [@Dimitri Dering](/t5/user/viewprofilepage/user-id/4853938). Please make sure to mark this question as Resolved.


Tags: yaml