Bamboo release version creation via REST API problem
Asked by tnt4brain:

Hi everyone!  

My question is all about Bamboo REST API.  

When I try to create new release via REST API, I get a strange error, and I really see no way to fix it (googled a whole lot, please believe me).  

The request itself is set up as per [documentation](https://docs.atlassian.com/atlassian-bamboo/REST/6.9.2/#d2e2619 "Exact link to Bamboo REST API spec"):   

curl -H "Content-Type: application/json" -H "Accept: application/json" -u ${bamboo_CI_LOGIN}:${bamboo_CI_PASSWORD} -X POST "[https://bamboo.\<domain_name\>/rest/api/latest/deploy/project/${DEPLOY_ID}/version]()" --verbose -d @- \<\< EOF  
{  
"planResultKey": "**\<build_plan_result_key\>** -**\<buildnumber\>** ",  
"name": "sometest-1",  
"nextVersionName": "sometest-2"  
}  
EOF  

But I get an obscure message for the response that actually explains nothing:  

"Can not create version, passed result **\<build_plan_result_key\>** has different master than plan associated with deployment project **\<build_plan_key\>** "  

What is wrong with it? My deployment project is definitely linked with "**master** " branch, but I can create releases via UI without any need of changing project configuration, just select another branch and its build result and voila! - a fresh new release is here and being deployed.   

So what should I do to be able to create release from build results without that nagging error?


Answers:
author: Alexey Chystoprudov
body: This error message means that **build_plan_result_key** and **build_plan_key** not belong to same master plan, e.g. they don't have common ancestor or **build_plan_key** don't have plan branch builds with given **build_plan_result_key**

comments: author: tnt4brain
body: I'm sorry, but I should admit you're utterly wrong.

I've came across the situation during a new release creation investigation from 'develop' branch result of the build plan that definitely has 'master' branch.

I'd be perfectly happy to see the link to REST API documentation which explains or even mentions this behavior that renders this given endpoint completely useless, as I cannot see [any plan/branch/linked plan etc. mentions](https://docs.atlassian.com/atlassian-bamboo/REST/6.9.2/#d2e1684 "Bamboo REST API documentation by Atlassian").

Meanwhile, I've managed to find out that there's a pretty good API call **without** all those vague undocumented requirements.

The endpoint that works is "[https://bamboo.\<domainname\>/deploy/doCreateDeploymentVersion.action]()", and here's the parameter list:  
linkedPlanKey=${BUILDPLANKEY}, deploymentReleaseBranch=${BUILDPLANKEY},  
deploymentProjectId=${DEPLOY_ID},  
buildResult=${BUILDPLANKEY}-${BUILDNUMBER},  
versionName=${RELEASE_NAME},  
save=Create+release,  
bamboo.successReturnMode=json

That's it, and it binds no requirements on me.  

The current endpoint implementation requires some obscure conditions that are even undocumented; however, the purpose of this endpoint is definitely clear: I've a build key for a given build result, and I want to create a release. The same is done via UI routinely and without any efforts, so why this pure-backend call can't do the same? I wonder if you could you please consider implementing this behaviour in the REST API I've mentioned earlier?


author: Alexey Chystoprudov
body: I'm sorry to hear about misbehaviour of REST endpoint you mentioned. It was designed exactly to avoid usage of doCreateDeploymentVersion.action and have same functionality.

May I ask you to report support case so we could check reasons it doesn't work at your environment


author: tnt4brain
body: Yes, sure: our support agreement is in effect.


author: tommaso.paoletto
body: Hi [@tnt4brain](/t5/user/viewprofilepage/user-id/277816) and [@Alexey Chystoprudov](/t5/user/viewprofilepage/user-id/781646) ,

did you find some way to get the API working in the expected way?

We have the exact same situation and used the same workaround to create releases from "non linked build branches".


author: Alexey Chystoprudov
body: Hi [@tommaso.paoletto](/t5/user/viewprofilepage/user-id/5006332) , I've just checked if REST endpoint works as expected at latest 8.2.5 Bamboo

I have build with 2 plan branches, master (TEST-TEST) and dev (TEST-TEST0). I have deployment project linked to master branch.

Then I created version from second build of dev branch which has TEST-TEST0-2 plan result key with command

```
curl -u admin:admin -X POST --header 'Content-Type: application/json' \
--url http://localhost:6990/bamboo/rest/api/latest/deploy/project/1671169/version \
-d '{"name": "my_version_1","nextVersionName":"my_version_2","planResultKey":"TEST-TEST0-2"}'
```

Response is

```
{
  "id": 4489217,
  "name": "my_version_1",
  "creationDate": 1661177481915,
  "creatorUserName": "admin",
  "items": [
    {
      "id": 4554753,
      "name": "text",
      "planResultKey": {
        "key": "TEST-TEST0-2",
        "entityKey": {
          "key": "TEST-TEST0"
        },
        "resultNumber": 2
      },
      "type": "BAM_ARTIFACT",
      "label": "text",
      "location": "",
      "copyPattern": "*.txt",
      "size": 3,
      "artifact": {
        "id": 4423682,
        "label": "text",
        "size": 3,
        "isSharedArtifact": true,
        "isGloballyStored": false,
        "linkType": "com.atlassian.bamboo.plugin.artifact.handler.local:ServerLocalArtifactHandler",
        "planResultKey": {
          "key": "TEST-TEST0-2",
          "entityKey": {
            "key": "TEST-TEST0"
          },
          "resultNumber": 2
        },
        "archiverType": "NONE"
      }
    }
  ],
  "operations": {
    "canView": true,
    "canViewConfiguration": true,
    "canEdit": true,
    "canDelete": true,
    "allowedToExecute": false,
    "canExecute": false,
    "allowedToCreateVersion": true,
    "allowedToSetVersionStatus": true
  },
  "creatorDisplayName": "admin",
  "creatorGravatarUrl": "https://secure.gravatar.com/avatar/64e1b8d34f425d19e1ee2ea7236d3028?r=g&s=24&d=mm",
  "planBranchName": "dev",
  "ageZeroPoint": 1661177481915,
  "deploymentProjectId": 1671169
}
```

Please let me know if you have different setup and your Bamboo version