Commits

Joe Clark committed 4438782 Merge

Merged in nbhawnani/bamboo-continuous-plugin-deployment (pull request #3)

Disable running on branch builds by default. Add option to enable if necessary.

  • Participants
  • Parent commits 198eab0, 57e5f72

Comments (0)

Files changed (5)

File src/main/java/com/atlassian/bamboo/plugins/confdeploy/AutoDeployConfigurator.java

     private static final Set<String> FIELDS_TO_COPY = Sets.newHashSet(
             AutoDeployTask.PLUGIN_ARTIFACT,
             AutoDeployTask.CONFLUENCE_BASE_URL,
-            AutoDeployTask.CONFLUENCE_ADMIN_USER
+            AutoDeployTask.CONFLUENCE_ADMIN_USER,
+            AutoDeployTask.BRANCH_ENABLED
     );
 
     /**
         final Map<String, String> config = super.generateTaskConfigMap(params, previousTaskDefinition);
         config.put(AutoDeployTask.CONFLUENCE_BASE_URL, params.getString(AutoDeployTask.CONFLUENCE_BASE_URL));
         config.put(AutoDeployTask.CONFLUENCE_ADMIN_USER, params.getString(AutoDeployTask.CONFLUENCE_ADMIN_USER));
+        config.put(AutoDeployTask.BRANCH_ENABLED, String.valueOf(params.getBoolean(AutoDeployTask.BRANCH_ENABLED)));
 
         // Encrypt the password before persisting
         final String rawPassword = params.getString(AutoDeployTask.CONFLUENCE_ADMIN_PASSWORD);
             context.put(AutoDeployTask.PLUGIN_ARTIFACT, artifacts.get(0)); // select a default
 
         context.put(AutoDeployTask.CONFLUENCE_BASE_URL, "eg. 'http://localhost:1990/confluence'");
+        context.put(AutoDeployTask.BRANCH_ENABLED, String.valueOf(false)); // run off branch builds by default
     }
 
     /**

File src/main/java/com/atlassian/bamboo/plugins/confdeploy/AutoDeployTask.java

 
 import com.atlassian.bamboo.build.logger.BuildLogger;
 import com.atlassian.bamboo.plan.artifact.ArtifactSubscriptionContext;
-import com.atlassian.bamboo.plan.artifact.ArtifactSubscriptionManager;
 import com.atlassian.bamboo.task.TaskContext;
 import com.atlassian.bamboo.task.TaskException;
 import com.atlassian.bamboo.task.TaskResult;
 import com.atlassian.bamboo.task.TaskResultBuilder;
 import com.atlassian.bamboo.task.TaskType;
+import com.atlassian.bamboo.v2.build.BuildContext;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
     public static final String CONFLUENCE_BASE_URL = "confDeployURL";
     public static final String CONFLUENCE_ADMIN_USER = "confDeployUsername";
     public static final String CONFLUENCE_ADMIN_PASSWORD = "confDeployPassword";
+    public static final String BRANCH_ENABLED = "deployBranchEnabled";
     public static final String CONFLUENCE_KEY = "confDeployKey";
 
     private static final String ENDPOINT_RELATIVE_URL = "rpc/soap-axis/confluenceservice-v2";
 
         // Extract the required parameters
         final String confluenceBaseURL = taskContext.getConfigurationMap().get(CONFLUENCE_BASE_URL);
+        final boolean branchEnabled = taskContext.getConfigurationMap().getAsBoolean(BRANCH_ENABLED);
         final String actualURL = urlConcat(confluenceBaseURL, ENDPOINT_RELATIVE_URL);
 
         final String username = taskContext.getConfigurationMap().get(CONFLUENCE_ADMIN_USER);
         // TODO: Retrieve the artifact subscription by ID
         //final ArtifactSubscription pluginArtifact = artifactSubscriptionManager.findSubscription(Long.valueOf(artifactKey));
 
+        // Only run for branch builds if the user has asked to do so
+        BuildContext buildContext = taskContext.getBuildContext();
+        if (!branchEnabled && buildContext.isBranch())
+        {
+            buildLogger.addBuildLogEntry("Plugin deployment task has been disabled for branch builds.");
+            return TaskResultBuilder.create(taskContext).success().build();
+        }
+
         // Ensure that the artifact exists and is accessible.
         File pluginJar = null;
-        for (ArtifactSubscriptionContext context : taskContext.getBuildContext().getArtifactContext().getSubscriptionContexts())
+        for (ArtifactSubscriptionContext context : buildContext.getArtifactContext().getSubscriptionContexts())
         {
             if (context.getArtifactDefinitionContext().getName().equals(artifactKey))
             {
         }
         if (pluginJar == null)
         {
-            final String msg = String.format("Unable to find the artifact with id %s in this task's context", artifactKey);
+            final String msg = String.format("Unable to find the artifact with id %s in this task's context. " +
+                "Has an artifact subscription been configured for that artifact in this job?", artifactKey);
             buildLogger.addErrorLogEntry(msg);
             throw new TaskException(msg);
         }
 
         return TaskResultBuilder.create(taskContext).success().build();
     }
-}
+}

File src/main/resources/editTask.ftl

 [@ww.textfield cssClass="long-field" labelKey="confdeploy.url" name="confDeployURL" required="true" /]
 [@ww.textfield cssClass="long-field" labelKey="confdeploy.username" name="confDeployUsername" required="true"/]
 [@ww.password cssClass="long-field" labelKey="confdeploy.password" name="confDeployPassword" required="true" /]
-
-
-
-
+[@ww.checkbox cssClass="long-field" labelKey="deploy.branch.enabled" name="deployBranchEnabled" toggle="true"/]

File src/main/resources/english.properties

 confdeploy.password.description = Atlassian Application System Administrator password
 confdeploy.password.error = Password must be specified
 
-
+deploy.branch.enabled = Run on branch builds
+deploy.branch.enabled.description = Whether or not to run for branch builds
+deploy.branch.enabled.error = Run on branch builds is invalid

File src/main/resources/viewTask.ftl

 [@ww.label labelKey="confdeploy.jar" name="confDeployJar" /]
 [@ww.label labelKey="confdeploy.url" name="confDeployURL" /]
-[@ww.label labelKey="confdeploy.username" name="confDeployUsername" /]
+[@ww.label labelKey="confdeploy.username" name="confDeployUsername" /]
+[@ww.label labelKey="deploy.branch.enabled" name="deployBranchEnabled" /]