Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can i add new environment with bamboo specs in deployment without overwrite an existing project?

The Watcher
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 22, 2025

Hi,

I would like to add a new Environment to an existing Deployment Project using Java Bamboo Specs.

When I pass the same bambooProjectKey, bambooPlanKey, and the same name to the PlanIdentifier, instead of creating a new environment, it overwrites the existing published one. That is not what I want. My goal is to keep the existing deployment project and only add a new environment to it.

Here is the code snippet I am using:

 

 Environment preProdEnv = new Environment("PRE-PROD")
                .description("Pre Production Environment")
                .triggers(new AfterSuccessfulBuildPlanTrigger())   // trigger optional
                .tasks(
                        new CleanWorkingDirectoryTask(),
                        new VcsCheckoutTask()
                                .description("Checkout Helm Repository")
                                .checkoutItems(new CheckoutItem().repository("nds-helm-repository")),
                        new ScriptTask()
                                .description("Deploy PRE-PROD")
                                .inlineBody("echo 'Deploying to PRE-PROD environment...'")
                );

        // update deployment project dengan env baru
        return new Deployment(planId, DEPLOYMENT_PROJECT_NAME)
                .releaseNaming(new com.atlassian.bamboo.specs.api.builders.deployment.ReleaseNaming("release-518").autoIncrement(true))
                .updateEnvironment(preProdEnv); <<the method is undefined

The issue is that updateEnvironment does not exist in the API.

👉 Is there a way to add a new environment to an already published deployment project using Bamboo Specs, without overwriting the existing project?

This is quite urgent, so any guidance would be really appreciated.

Thank you,

1 answer

1 accepted

1 vote
Answer accepted
Shashank Kumar
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 22, 2025

Hello Watcher,

Welcome to Atlassian community.

Below is an example of what you are trying to achieve. You can use this and setup your specs.

 

import com.atlassian.bamboo.specs.api.BambooSpec;
import com.atlassian.bamboo.specs.api.builders.BambooOid;
import com.atlassian.bamboo.specs.api.builders.deployment.Deployment;
import com.atlassian.bamboo.specs.api.builders.deployment.Environment;
import com.atlassian.bamboo.specs.api.builders.deployment.ReleaseNaming;
import com.atlassian.bamboo.specs.api.builders.permission.DeploymentPermissions;
import com.atlassian.bamboo.specs.api.builders.permission.EnvironmentPermissions;
import com.atlassian.bamboo.specs.api.builders.permission.PermissionType;
import com.atlassian.bamboo.specs.api.builders.permission.Permissions;
import com.atlassian.bamboo.specs.api.builders.plan.PlanIdentifier;
import com.atlassian.bamboo.specs.builders.task.ArtifactDownloaderTask;
import com.atlassian.bamboo.specs.builders.task.CleanWorkingDirectoryTask;
import com.atlassian.bamboo.specs.builders.task.DownloadItem;
import com.atlassian.bamboo.specs.builders.task.ScriptTask;
import com.atlassian.bamboo.specs.util.BambooServer;

@BambooSpec
public class PlanSpec {

public Deployment rootObject() {
final Deployment rootObject = new Deployment(new PlanIdentifier("SCRIP", "TEST")
.oid(new BambooOid("xj6quyqtw0ld")),
"ServerDeployment")
.oid(new BambooOid("xjj7ufxjde69"))
.description("JH")
.releaseNaming(new ReleaseNaming("release-20")
.autoIncrement(true))
.environments(new Environment("PROD")
.tasks(new CleanWorkingDirectoryTask(),
new ArtifactDownloaderTask()
.description("Download release contents")
.artifacts(new DownloadItem()
.allArtifacts(true)),
new ScriptTask()
.inlineBody("echo \"ehhlo\"")),
new Environment("UAT")
.tasks(new CleanWorkingDirectoryTask(),
new ArtifactDownloaderTask()
.description("Download release contents")
.artifacts(new DownloadItem()
.allArtifacts(true)),
new ScriptTask()
.inlineBody("echo \"ehhlo\"")));
return rootObject;
}

public DeploymentPermissions deploymentPermission() {
final DeploymentPermissions deploymentPermission = new DeploymentPermissions("ServerDeployment")
.permissions(new Permissions()
.userPermissions("skumar14", PermissionType.VIEW, PermissionType.EDIT, PermissionType.CLONE, PermissionType.ADMIN, PermissionType.VIEW_CONFIGURATION, PermissionType.APPROVE_RELEASE, PermissionType.CREATE_RELEASE));
return deploymentPermission;
}

public EnvironmentPermissions environmentPermission1() {
final EnvironmentPermissions environmentPermission1 = new EnvironmentPermissions("ServerDeployment")
.environmentName("PROD")
.permissions(new Permissions()
.userPermissions("skumar14", PermissionType.VIEW, PermissionType.EDIT, PermissionType.BUILD, PermissionType.VIEW_CONFIGURATION));
return environmentPermission1;
}

public EnvironmentPermissions environmentPermission2() {
final EnvironmentPermissions environmentPermission2 = new EnvironmentPermissions("ServerDeployment")
.environmentName("UAT")
.permissions(new Permissions()
.userPermissions("skumar14", PermissionType.VIEW, PermissionType.EDIT, PermissionType.BUILD, PermissionType.VIEW_CONFIGURATION));
return environmentPermission2;
}

public static void main(String... argv) {
//By default credentials are read from the '.credentials' file.
BambooServer bambooServer = new BambooServer("http://10.10.0.4:8085");
final PlanSpec planSpec = new PlanSpec();

final Deployment rootObject = planSpec.rootObject();
bambooServer.publish(rootObject);

final DeploymentPermissions deploymentPermission = planSpec.deploymentPermission();
bambooServer.publish(deploymentPermission);

final EnvironmentPermissions environmentPermission1 = planSpec.environmentPermission1();
bambooServer.publish(environmentPermission1);

final EnvironmentPermissions environmentPermission2 = planSpec.environmentPermission2();
bambooServer.publish(environmentPermission2);
}
}

 Regards,

Shashank Kumar

The Watcher
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 25, 2025

Hello Shashank,

Thank you for the example. I was able to try it, but I noticed that when I publish the Bamboo Specs, it still overwrites the existing environments instead of updating them.

Is there a way to keep the existing environments and only add or update specific ones without replacing everything?

 

package basebamboo.v1;

import com.atlassian.bamboo.specs.api.BambooSpec;
import com.atlassian.bamboo.specs.api.builders.BambooOid;
import com.atlassian.bamboo.specs.api.builders.deployment.Deployment;
import com.atlassian.bamboo.specs.api.builders.deployment.Environment;
import com.atlassian.bamboo.specs.api.builders.deployment.ReleaseNaming;
import com.atlassian.bamboo.specs.api.builders.permission.DeploymentPermissions;
import com.atlassian.bamboo.specs.api.builders.permission.EnvironmentPermissions;
import com.atlassian.bamboo.specs.api.builders.permission.PermissionType;
import com.atlassian.bamboo.specs.api.builders.permission.Permissions;
import com.atlassian.bamboo.specs.api.builders.plan.PlanIdentifier;
import com.atlassian.bamboo.specs.builders.task.CleanWorkingDirectoryTask;
import com.atlassian.bamboo.specs.builders.task.ScriptTask;
import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask;
import com.atlassian.bamboo.specs.builders.task.CheckoutItem;
import com.atlassian.bamboo.specs.util.BambooServer;

@BambooSpec
public class AddEnvToExistingDeploymentSpec {

    // --- Deployment utama (sesuai gaya rootObject) ---
    public Deployment rootObject() {
        final Deployment rootObject = new Deployment(
                new PlanIdentifier("test", "Test2") // Project key + Plan key
                        .oid(new BambooOid("1c3xe7ebeqnrq")), // dummy OID, bisa diganti sesuai Bamboo
                "Deployment for nds-ui-test") // Deployment Project Name
                .oid(new BambooOid("1c49v6vi46vgj")) // dummy OID, bisa diganti sesuai Bamboo
                .description("Deployment project untuk nds-ui-test")
                .releaseNaming(new ReleaseNaming("release-518").autoIncrement(true))
                .environments(
                        new Environment("PRE-PROD")
                                .description("Pre Production Environment")
                                .tasks(
                                        new CleanWorkingDirectoryTask(),
                                        new VcsCheckoutTask()
                                                .description("Checkout Helm Repository")
                                                .checkoutItems(
                                                        new CheckoutItem().repository("nds-helm-repository")
                                                ),
                                        new ScriptTask()
                                                .description("Deploy PRE-PROD")
                                                .inlineBody("echo 'Deploying to PRE-PROD environment...'")
                                )
                );
               
        return rootObject;
    }

    // --- Deployment-level Permissions ---
    public DeploymentPermissions deploymentPermissions() {
        return new DeploymentPermissions("Deployment for nds-ui-test")
                .permissions(
                        new Permissions()
                                .userPermissions("00351356",
                                        PermissionType.EDIT,
                                        PermissionType.VIEW,
                                        PermissionType.VIEW_CONFIGURATION)
                                .userPermissions("00361923",
                                        PermissionType.EDIT,
                                        PermissionType.VIEW,
                                        PermissionType.VIEW_CONFIGURATION)
                );
    }

    // --- Environment-level Permissions (PRE-PROD) ---
    public EnvironmentPermissions environmentPermissionPreProd() {
        return new EnvironmentPermissions("Deployment for nds-ui-test")
                .environmentName("PRE-PROD")
                .permissions(
                        new Permissions()
                                .userPermissions("00351356",
                                        PermissionType.EDIT,
                                        PermissionType.BUILD,
                                        PermissionType.VIEW)
                                .userPermissions("00361923",
                                        PermissionType.EDIT,
                                        PermissionType.BUILD,
                                        PermissionType.VIEW)
                );
    }

    // --- Main ---
    public static void main(String[] args) throws Exception {
        AddEnvToExistingDeploymentSpec spec = new AddEnvToExistingDeploymentSpec();
        Deployment deployment = spec.rootObject();
        DeploymentPermissions depPerm = spec.deploymentPermissions();
        EnvironmentPermissions envPerm = spec.environmentPermissionPreProd();

        BambooServer bambooServer = new BambooServer("https://128.21.33.1:8085");
        Object result1 = bambooServer.publish(deployment);
        Object result2 = bambooServer.publish(depPerm);
        Object result3 = bambooServer.publish(envPerm);

        System.out.println("DEPLOYMENT PUBLISH RESULT: " + result1);
        System.out.println("DEPLOYMENT PERMISSION RESULT: " + result2);
        System.out.println("ENV PERMISSION RESULT: " + result3);

        System.exit(0);
    }
}

 

Best regards,
The Watcher

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events