Create a simple plan with Bamboo Specs fails on local bamboo instance Edited

Hello. I followed tutorial https://confluence.atlassian.com/bamboo/tutorial-create-a-simple-plan-with-bamboo-specs-894743911.html Trying to test locally on my server. I use Test license for plugin developers.

How to create a bamboo plan from java code with bamboo specs.

private Plan createPlan() {
    return new Plan(
            project(),
            "Plan Name", "PLANKEY")
            .description("Plan created from (enter repository url of your plan)")
            .stages(
                    new Stage("Stage 1")
                            .jobs(new Job("Build & run", "RUN")
                                    .tasks(
                                            new ScriptTask().inlineBody("echo Hello world!"))));
}
Plan plan = new PlanSpec().createPlan();

bambooServer.publish(plan);

 

After executing project I observed error:

Caused by: com.atlassian.bamboo.specs.exceptions.BambooSpecsRestRequestException: null for uri: http://local:6990/bamboo/rest/api/latest/import/plan

 

2018-01-09 16:30:38,583 DEBUG [FileUserPasswordCredentials] Looking for credentials file: /testingPlatformIntergrationTest/bamboo-specs/.credentials

2018-01-09 16:30:38,587 DEBUG [FileUserPasswordCredentials] Credentials file found: testingPlatformIntergrationTest/bamboo-specs/.credentials

2018-01-09 16:30:38,629 INFO [BambooServer] Publishing plan PRJ-PLANKEY

2018-01-09 16:30:39,227 INFO [BambooServer] An error occurred while publishing plan PRJ-PLANKEY: null for uri: http://local:6990/bamboo/rest/api/latest/import/plan

2018-01-09 16:30:39,227 DEBUG [BambooServer] {"message":"null for uri: http://local:6990/bamboo/rest/api/latest/import/plan","status-code":404}

It looks like method "import" not available in REST API.

Expected results: from that tutorial new created plan in bamboo

 

Please, can somebody check it? Thanks in advance.

Best regards,

Eugene

1 answer

This widget could not be displayed.

Hi Eugene,

The HTTP status 404 which is "not found" could you please check if the Bamboo URL which you are using is correct:

http://local:6990

Should this be "localhost" instead of "local"? Just pointing in case of typo.

Apart from this, I couldn't see the similar code in your description:

BambooServer bambooServer = new BambooServer("http://localhost:8125/623");

Which actually contains the Bamboo URL to push the changes.

 

I am sharing my code as a sample to refer:

 

package com.my.company;

 

import com.atlassian.bamboo.specs.api.BambooSpec;

import com.atlassian.bamboo.specs.api.builders.plan.Plan;

import com.atlassian.bamboo.specs.api.builders.plan.PlanIdentifier;

import com.atlassian.bamboo.specs.api.builders.project.Project;

import com.atlassian.bamboo.specs.util.BambooServer;

import com.atlassian.bamboo.specs.api.builders.permission.Permissions;

import com.atlassian.bamboo.specs.api.builders.permission.PermissionType;

import com.atlassian.bamboo.specs.api.builders.permission.PlanPermissions;

import com.atlassian.bamboo.specs.api.builders.plan.Job;

import com.atlassian.bamboo.specs.api.builders.plan.Stage;

import com.atlassian.bamboo.specs.api.builders.plan.artifact.Artifact;

import com.atlassian.bamboo.specs.api.builders.repository.VcsRepository;

import com.atlassian.bamboo.specs.builders.repository.git.GitRepository;

import com.atlassian.bamboo.specs.builders.task.ScriptTask;

import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask;

 

/**

* Plan configuration for Bamboo.

* Learn more on: <a href="https://confluence.atlassian.com/display/BAMBOO/Bamboo+Specs">https://confluence.atlassian.com/display/BAMBOO/Bamboo+Specs</a>

* Test Comment by Robhit

*/

@BambooSpec

public class PlanSpec {

 

    /**

     * Run main to publish plan on Bamboo

     */

    public static void main(final String[] args) throws Exception {

        //By default credentials are read from the '.credentials' file.

        BambooServer bambooServer = new BambooServer("http://localhost:8125/623");

 

        Plan plan = new PlanSpec().createPlan();

 

        bambooServer.publish(plan);

 

        PlanPermissions planPermission = new PlanSpec().createPlanPermission(plan.getIdentifier());

 

        bambooServer.publish(planPermission);

    }

 

    PlanPermissions createPlanPermission(PlanIdentifier planIdentifier) {

        Permissions permission = new Permissions()

                .userPermissions("robhit", PermissionType.ADMIN, PermissionType.CLONE, PermissionType.EDIT)

                .groupPermissions("bamboo-admin", PermissionType.ADMIN)

                .loggedInUserPermissions(PermissionType.VIEW)

                .anonymousUserPermissionView();

        return new PlanPermissions(planIdentifier.getProjectKey(), planIdentifier.getPlanKey()).permissions(permission);

    }

 

    Project project() {

        return new Project()

                .name("Project Name")

                .key("PRJ");

    }

 

    Plan createPlan() {

        return new Plan(

                project(),

                "Plan Name", "PLANKEY")

                .description("Plan created from (enter repository url of your plan)")

                .planRepositories(

                        gitRepository()

                )

                .stages(

                        new Stage("Stage 1").jobs(

                                new Job("Job Name", "JOBKEY")

                                        .tasks(

                                                gitRepositoryCheckoutTask(),

                                                scriptTask()

                                        )

                                        .artifacts(artifact())

                        )

                );

    }

 

    VcsRepository gitRepository() {

        return new GitRepository()

                .name("your-git-repository")

                .url("git@bitbucket.org:your-company/your-repository.git")

                .branch("master");

    }

 

    VcsCheckoutTask gitRepositoryCheckoutTask() {

        return new VcsCheckoutTask()

                .addCheckoutOfDefaultRepository();

    }

 

    ScriptTask scriptTask() {

        return new ScriptTask()

                .inlineBody("mkdir target; echo 'hello world' > target/console.out")

                .interpreterShell();

    }

 

    Artifact artifact() {

        return new Artifact("Build results")

                .location("target")

                .copyPattern("**/*");

    }

 

}

Hope this will help.

Thanks!

Hey Robhit Saxena. Thanks for the reply. During reviewing you code I found that I used old version of bamboo instance.

 

After upgrading to the latest bamboo version, import of new plan works. Seems that in my version that functionality was not there. I mean REST API was different.

 

Thanks again for the hint.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

76 views 0 1
Join discussion

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