get bamboo project key using curl

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

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.

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

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?

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

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.

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,070 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot