Bamboo YAML spec not working when I use with plan repo
Asked by Mohan L:

Hi All,

I am using YAML spec with Atlassian Bamboo version 8.0.6 and configured plan repository with in the YAML spec. Please find the steps I used and error message.

How to pass empty passphrase? or what is workaround for this issue?

Any help will be greatly appreciated.

1). Generated SSH key

ssh-keygen -t ed25519 -C "l.xxxx@gmail.com"

<br />

2). Configured public key on Bitbucket server project level.

3). My plan repository YAML spec looks like below. sshKey_devops_public_key and bamboo.sshKey_devops_private_key are global variables. Used passphrase while generating SSH key.

repositories:  
- spec-repo:  
scope: global  
- app-repo:  
type: bitbucket-server  
server: Bitbucket  
project: DEV  
slug: simple-java-maven-app  
clone-url: ssh://git@xxxxxx:7999/dev/xxxx-app.git  
public-key: ${bamboo.sshKey_devops_public_key}  
private-key: ${bamboo.sshKey_devops_private_key}  
branch: master  
command-timeout-minutes: '180'  
use-shallow-clones: 'false'  
cache-on-agents: 'false'  
submodules: 'false'  
verbose-logs: 'false'  
fetch-all: 'false'  
lfs: 'false'  
viewer: com.atlassian.bamboo.plugins.stash.atlassian-bamboo-plugin-stash:bbServerViewer

The above YAML spec not working and getting below error.

17-Apr-2022 01:41:20 java.lang.IllegalArgumentException: Cannot read keypair, passphrase wasn't set.

Here is the link to full error message: <https://pastebin.com/8LXC69Z3>


Answers:
author: Eduardo Alvarenga
body: Hello [@Mohan L](/t5/user/viewprofilepage/user-id/925019)

Please check the following question that shows some good tips on using git and bitbucket type repositories.

* <https://community.atlassian.com/t5/Bamboo-questions/Bamboo-yaml-spec-create-plan-repositories/qaq-p/1991934>

Regards,

Eduardo Alvarenga  
Atlassian Support APAC

comments: author: Mohan L
body: Hi [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410) ,

It works when I hard code public-key and private-key values in YAML spec like below:

public-key: \<hard code public key\>

private-key: \<Hard code Bamboo encrypted private key\>

However I am getting same "java.lang.IllegalArgumentException: Cannot read keypair, passphrase wasn't set" when I try to create global variable with the public key and Bamboo encrypted private key.

Is there any way to keep the public and private key values out of YAML spec and reference in the spec instead of hard code it?

public-key: ${bamboo.sshKey_devops_public_key}

private-key: ${bamboo.sshKey_devops_private_key}

Thanks

Mohan


author: Eduardo Alvarenga
body: Hello [@Mohan L](/t5/user/viewprofilepage/user-id/925019)

Bamboo will interpret the public-key and private-key fields as strings and will not expand variables there. If you want to have dynamic authentication you can use Global Shared credentials or Project Shared credentials -- available in Bamboo Data Center only.

* [Shared credentials](https://confluence.atlassian.com/bamboo/shared-credentials-424313357.html)
* <https://docs.atlassian.com/bamboo-specs-docs/8.0.6/specs.html?yaml#git-authentication>

Note: Your SSH private key needs to be converted to PEM format before getting added to Bamboo Shared credentials. Something like this will do the job:

```
openssl rsa -in id_rsa -outform pem > id_rsa.pem
```

Example:

```
- Calibration-git-local:
    type: git
    url: ssh://git@git.mydomain.net:7999/cal/calibration.git
    branch: master
    shared-credentials: shared-ssh-key
```

And then I have a Shared credential called **shared-ssh-key** of type **SSH** in Bamboo.

Regards,

Eduardo Alvarenga  
Atlassian Support APAC


author: Mohan L
body: Hi [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410) ,

Thanks for your time.

1). Converted private key to converted to PEM format

2). Created shared-ssh-key in global shared credentials

3). spec looks like below:

The error turned "Document structure is incorrect".

Does bitbucket-server type support shared-credentials?

```
repositories:
- spec-repo:
    scope: global
- app-repo:
    type: bitbucket-server
    server: Bitbucket
    project: DEV
    slug: simple-java-maven-app
    clone-url: ssh://git@xxxxxx:7999/dev/simple-java-maven-app.git
    shared-credentials: shared-ssh-key
    branch: master
    command-timeout-minutes: '180'
    use-shallow-clones: 'false'
    cache-on-agents: 'false'
    submodules: 'false'
    verbose-logs: 'false'
    fetch-all: 'false'
    lfs: 'false'
    viewer: com.atlassian.bamboo.plugins.stash.atlassian-bamboo-plugin-stash:bbServerViewer

```

```


17-Apr-2022 07:43:47 Bamboo YAML import failed: Document structure is incorrect: Found following unused properties: repositories / [1] / app-repo / shared-credentials, repositories / [1] / app-repo / branch, repositories / [1] / app-repo / command-timeout-minutes, repositories / [1] / app-repo / use-shallow-clones, repositories / [1] / app-repo / cache-on-agents, repositories / [1] / app-repo / submodules, repositories / [1] / app-repo / verbose-logs, repositories / [1] / app-repo / fetch-all, repositories / [1] / app-repo / lfs, repositories / [1] / app-repo / viewer.17-Apr-2022 07:43:47 Every property must have a correct key recognizable by Bamboo and must be used as part of the configuration in the current YAML document. Common sources of these problems are typos in properties keys, unused jobs, and mixing a plan and its permissions configuration in one YAML document.17-Apr-2022 07:43:47 17-Apr-2022 07:43:47 17-Apr-2022 07:43:47 Do you need help? Please visit http://docs.atlassian.com/bamboo/docs-0800/Bamboo+Specs+troubleshooting17-Apr-2022 07:43:47 
```

Thanks

Mohan


author: Eduardo Alvarenga
body: Hello [@Mohan L](/t5/user/viewprofilepage/user-id/925019)

As the error states you have a few issues, I can highlight this one:

* **repositories / \[1\] / app-repo / shared-credentials**

The "***shared-credentials*** " property is only valid if used along with "*git* " type repositories. When using a "*bitbucket-server*" type repository, Bamboo expects that you declare the following information:
> When using Bamboo Specs in interactive mode, the Bamboo server can and fetch the data such as clone url or SSH keys from the Bitbucket Server. In mode, it is not possible, as user session is not available during the automatic update. Therefore the following properties are **mandatory** when in mode:
>
> * **SSH private key** of the repository (the key can be defined in both [Bamboo Specs Encryption](https://confluence.atlassian.com/bamboo/bamboo-specs-encryption-970268127.html) and plain format).
> * **SSH public key** of the repository.
> * **SSH clone url** of this repository, as used by git commands (can be found on repository's page in Bitbucket Server).

**Source:** <https://docs.atlassian.com/bamboo-specs-docs/8.0.6/specs.html?yaml#creating-bitbucket-server-repositories-in-rss-mode>

#### So you have two choices: {#toc-hId-143592980}

* Use a *git type* repository along with *shared-credentials* . You may also be interested in configuring a [repository polling rule](https://docs.atlassian.com/bamboo-specs-docs/8.0.6/specs.html?yaml#polling-the-repository-for-changes) to allow Bamboo to retrieve changes from your Bitbucket repository periodically, or even [set a remote trigger](https://docs.atlassian.com/bamboo-specs-docs/8.0.6/specs.html?yaml#repository-triggers-a-build-on-commit) from your Bitbucket server back to your Bamboo instance.

or

* Use a *bitbucket-server type* repository and hardcode the SSH keys on the spec code. The declared private key can't have a passphrase (but it can be encrypted using [Bamboo Specs Encryption](https://confluence.atlassian.com/bamboo/bamboo-specs-encryption-970268127.html)).

Regards,

Eduardo Alvarenga  
Atlassian Support APAC


author: Jeffrey Cabierte
body: [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410) I need help with my concern about Bamboo Yaml Spec. May I know if you can help me figure out my concern please. Will you be free today or any from your team can see what is the issue here.

Thanks,

Jeff