Uploaded image for project: 'Bamboo Data Center'
  1. Bamboo Data Center
  2. BAM-18952

Unable to create new branches from pull requests with Bamboo Specs

XMLWordPrintable

      Summary

      Unable to create new branches from pull requests with Bamboo Specs

      Environment

      • Bamboo 6.2.3
      • Bitbucket Server

      Steps to Reproduce

      The script used to test out the behaviour:

      1. created a PlanSpecs.java with the following:
        PlanSpecs.java
        @BambooSpec
        public class PlanSpec {
            public static void main(final String[] args) throws Exception {
                BambooServer bambooServer = new BambooServer("http://localhost:8085");
                
                Plan plan = new Plan(new Project()
                        .key(new BambooKey("SPECS"))
                        .name("Bamboo Specs"),
                    "Temp",
                    new BambooKey("TMP"))
                    .enabled(false)
                    .pluginConfigurations(new ConcurrentBuilds()
                            .useSystemWideDefault(false))
                    .stages(new Stage("Default Stage")
                            .jobs(new Job("Default Job",
                                    new BambooKey("JOB1"))
                                    .tasks(new ScriptTask()
                                            .inlineBody("echo hello"))))
                    .linkedRepositories("Subversion")
                    
                    .planBranchManagement(new PlanBranchManagement()
                            .delete(new BranchCleanup())
                            .notificationForCommitters());
                
                bambooServer.publish(plan);
                
                PlanPermissions planPermission = new PlanPermissions(new PlanIdentifier("SPECS", "TMP"))
                    .permissions(new Permissions()
                            .userPermissions("admin"
                            		, PermissionType.EDIT
                            		, PermissionType.VIEW
                            		, PermissionType.ADMIN
                            		, PermissionType.CLONE
                            		, PermissionType.BUILD));
                
                bambooServer.publish(planPermission);
            }
        }
        

          The above creates a plan SPECS-TMP with a linked repository Subversion.

      2. then, we attempt on creating a new configuration against the same plan, replicaing the existent linked repository with a Bitbucket server one:
        PlanSpecs.java
        @BambooSpec
        public class PlanSpec {
        
            /**
             * Run main to publish plan on Bamboo
             */
            public static void main(final String[] args) throws Exception {
                BambooServer bambooServer = new BambooServer("http://localhost:8085");
                
                Plan plan = new Plan(new Project()
                        .key(new BambooKey("SPECS"))
                        .name("Bamboo Specs"),
                    "Temp",
                    new BambooKey("TMP"))
                    .enabled(false)
                    .pluginConfigurations(new ConcurrentBuilds()
                            .useSystemWideDefault(false))
                    .stages(new Stage("Default Stage")
                            .jobs(new Job("Default Job",
                                    new BambooKey("JOB1"))
                                    .tasks(new ScriptTask()
                                            .inlineBody("echo hello"))))
                    .planRepositories(new BitbucketServerRepository()
                            .name("Repository")
                            .repositoryViewer(new BitbucketServerRepositoryViewer())
                            .server(new ApplicationLink()
                                    .name("[Bitbucket]")
                                    .id("c050add6-701f-31a5-a85c-079fad0cfd31"))
                            .projectKey("BRAN")
                            .repositorySlug("repository")
                            .sshPublicKey("SSH_PUBLIC_KEY")
                            .sshPrivateKey("SSH_PRIVATE_KEY")
                            .changeDetection(new VcsChangeDetection()))
                    
                    .planBranchManagement(new PlanBranchManagement()
                            .createForPullRequest()
                            .delete(new BranchCleanup()
                                .whenRemovedFromRepositoryAfterDays(7)
                                .whenInactiveInRepositoryAfterDays(30))
                            .notificationForCommitters()
                            .issueLinkingEnabled(false));
                
                bambooServer.publish(plan);
                
                PlanPermissions planPermission = new PlanPermissions(new PlanIdentifier("SPECS", "TMP"))
                    .permissions(new Permissions()
                            .userPermissions("admin"
                            		, PermissionType.EDIT
                            		, PermissionType.VIEW
                            		, PermissionType.ADMIN
                            		, PermissionType.CLONE
                            		, PermissionType.BUILD));
                
                bambooServer.publish(planPermission);
            }
        }
        

          The above attemps on replacing repository in plan SPECS-TMP with a plan repository from Bitbucket Server (application links).

        And the output generated from Bamboo Specs was:

        2017-12-05 15:32:57,091 INFO [BambooServer] Publishing plan SPECS-TMP
        2017-12-05 15:32:57,798 INFO [BambooServer] An error occurred while publishing plan SPECS-TMP: Plan branch / workflow: You can't change the default repository because automatic branch management for this plan is dependent on pull requests. Update plan's branching configuration to enable switching the default repository.
        2017-12-05 15:32:57,798 INFO [BambooServer] (for more information, enable more detailed logging with system property -Dbamboo.specs.log.level=DEBUG)
        Exception in thread "main" com.atlassian.bamboo.specs.api.exceptions.BambooSpecsPublishingException: An error occurred while publishing plan SPECS-TMP: Plan branch / workflow: You can't change the default repository because automatic branch management for this plan is dependent on pull requests. Update plan's branching configuration to enable switching the default repository.
        	at com.atlassian.bamboo.specs.util.BambooServer.translateRestException(BambooServer.java:178)
        	at com.atlassian.bamboo.specs.util.BambooServer.translateException(BambooServer.java:148)
        	at com.atlassian.bamboo.specs.util.BambooServer.publish(BambooServer.java:101)
        	at tutorial.PlanSpec.main(PlanSpec.java:109)
        Caused by: com.atlassian.bamboo.specs.exceptions.BambooSpecsRestRequestException: Plan branch / workflow: You can't change the default repository because automatic branch management for this plan is dependent on pull requests. Update plan's branching configuration to enable switching the default repository.
        	at com.atlassian.bamboo.specs.util.RestHelper.lambda$sendRequest$2(RestHelper.java:89)
        	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:222)
        	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164)
        	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:139)
        	at com.atlassian.bamboo.specs.util.RestHelper.sendRequest(RestHelper.java:92)
        	at com.atlassian.bamboo.specs.util.RestHelper.post(RestHelper.java:201)
        	at com.atlassian.bamboo.specs.util.SendQueue$1.run(SendQueue.java:23)
        

      Expected Results

      • The script runs succesffuly and changes are applied.

      Actual Results

      • No changes applied

      The below exception is thrown:

      {
          "message": "com.atlassian.bamboo.specs.api.exceptions.PropertiesValidationException:
      	Plan branch / workflow: You can't change the default repository because automatic 
      	branch management for this plan is dependent on pull requests. Update plan's branching 
      	configuration to enable switching the default repository.",
          "status-code": 400
      }
      

      Workaround

      1. existent repository(s) must be delete from existent plan
      2. rerun Bamboo Specs to create repository(s):
        PlanSpecs.java
        // e.g. create a plan repository from Application Link
        .planRepositories(new BitbucketServerRepository()
                .name("Repository")
                .repositoryViewer(new BitbucketServerRepositoryViewer())
                .server(new ApplicationLink()
                        .name("[Bitbucket]")
                        .id("c050add6-701f-31a5-a85c-079fad0cfd31"))
                .projectKey("BRAN")
                .repositorySlug("repository")
                .sshPublicKey("SSH_PUBLIC_KEY")
                .sshPrivateKey("SSH_PRIVATE_KEY")
                .changeDetection(new VcsChangeDetection()))
        
        .planBranchManagement(new PlanBranchManagement()
                .createForPullRequest()
                .delete(new BranchCleanup()
                    .whenRemovedFromRepositoryAfterDays(7)
                    .whenInactiveInRepositoryAfterDays(30))
                .notificationForCommitters()
                .issueLinkingEnabled(false))
        		
        // e.g. recreate the delete repository		
        .linkedRepositories("Subversion");
        

        Reference: https://docs.atlassian.com/bamboo-specs-docs/latest/#multiple-repositories

              mgardias Marcin Gardias
              roliveira@atlassian.com Ricardo
              Votes:
              5 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: