get bamboo project key using curl

phani phani August 24, 2014

Here is what I am trying to do:

If I query Bamboo Project name to Bamboo REST API using Curl , Expected output is: Project Key.

If I query Bamboo Plan Name to Bamboo REST API using Curl , Expected output is: plan key.

3 answers

1 accepted

0 votes
Answer accepted
Krystian Brazulewicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 26, 2014

For this particular scenario I'd query Bamboo REST to list all plans:

$BAMBOO_URL/rest/api/latest/plan

and then use the information from response (plan key + plan name) to populate your UI controls. Then you'll display plan name and store plan key.

phani phani August 27, 2014

Yes, thats what I did. But the problem with this method is... if a project is having more than 40 plans, I have write a script to basically iterate all plans to get a key for a plan.

Since this is simple query, thought there would a direct solution for it.

But, thanks for your Inputs.

0 votes
phani phani August 26, 2014

Its hard to explain, but try to put this way, my JIRA ticket is accepting two fileds that are related to Bamboo (1. Project Name 2. Plan Name). I am writing a script to auto execute the Bamboo Plan, based on the JIRA Ticket. For this I had to build a Bamboo Plan url (based on the Project Name or Plan Name that I am capturing from JIRA Ticket) which requires Bamboo Plan Key.

0 votes
Krystian Brazulewicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 25, 2014

Hi

The whole REST API is build the other way around. You're exepected to know the project/plan key and then you can get more detailed information. Example for plan BAM-FC:

curl --header "Accept: application/json" $BAMBOO_URL/rest/api/latest/plan/BAM-FC

will give you

{
    "expand": "actions,stages,branches,variableContext",
    "projectKey": "BAM",
    "projectName": "+core+ Bamboo",
    "project": {
        "key": "BAM",
        "name": "+core+ Bamboo",
        "link": {
            "href": "$BAMBOO_URL/rest/api/latest/project/BAM",
            "rel": "self"
        }
    },
    "description": "Our main CI test build.",
    "shortName": "A CI Tests Master",
    "buildName": "A CI Tests Master",
    "shortKey": "FC",
    "type": "chain",
    "enabled": true,
    "link": {
        "href": "$BAMBOO_URL/rest/api/latest/plan/BAM-FC",
        "rel": "self"
    },
    "isFavourite": false,
    "isActive": false,
    "isBuilding": false,
    "averageBuildTimeInSeconds": 3627,
    "actions": {
        "size": 1,
        "start-index": 0,
        "max-result": 1
    },
    "stages": {
        "size": 2,
        "start-index": 0,
        "max-result": 2
    },
    "branches": {
        "size": 25,
        "start-index": 0,
        "max-result": 25
    },
    "variableContext": {
        "size": 30,
        "max-results": 30
    },
    "key": "BAM-FC",
    "name": "+core+ Bamboo - A CI Tests Master",
    "planKey": {
        "key": "BAM-FC"
    }
}

Can you please explain why would you like to query REST API with plan name?

Erik Husby August 25, 2014

One good reason -- Bamboo does not display the Project/Plan keys any where except in the build log files.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events