@Override
  public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {
    EnvVars envVars = build.getEnvironment(listener);
    envVars.overrideAll(build.getBuildVariables());
    boolean result = true;

    for (PostBuildStackBean stack : stacks) {
      final CloudFormation cloudFormation =
          newCloudFormation(stack, build, envVars, listener.getLogger());
      /*CloudFormation cloudFormation = new CloudFormation(
      		listener.getLogger(),
      		stack.getStackName(),
      		"",
      		new HashMap<String, String>(),
      		0,
      		stack.getParsedAwsAccessKey(envVars),
      		stack.getParsedAwsSecretKey(envVars),
      		stack.getAwsRegion(),
      		false,
      		envVars
      );*/
      if (cloudFormation.create()) {
        LOGGER.info("Success");
      } else {
        LOGGER.warning("Failed");
        result = false;
      }
    }
    return result;
  }
  /** Create an {@link ArgumentListBuilder} to run the build, given command arguments. */
  private ArgumentListBuilder buildCmdLine(
      AbstractBuild build, Launcher launcher, BuildListener listener)
      throws IllegalArgumentException, InterruptedException, IOException {
    ArgumentListBuilder args = new ArgumentListBuilder();

    //		DescriptorImpl descriptor = (DescriptorImpl) getDescriptor();

    EnvVars env = build.getEnvironment(listener);
    env.overrideAll(build.getBuildVariables());

    SbtInstallation sbt = getSbt();
    if (sbt == null) {
      throw new IllegalArgumentException("sbt-launch.jar not found");
    } else {
      Node currentNode = Computer.currentComputer().getNode();
      sbt = sbt.forNode(currentNode, listener);
      sbt = sbt.forEnvironment(env);

      String launcherPath = sbt.getSbtLaunchJar(launcher);

      if (launcherPath == null) {
        throw new IllegalArgumentException("sbt-launch.jar not found");
      }

      if (!launcher.isUnix()) {
        args.add("cmd.exe", "/C");
      }

      // java
      String javaExePath = (File.separatorChar == '\\') ? "java.exe" : "java";

      JDK jdk = build.getProject().getJDK();
      if (jdk != null) { // just in case were not in a build
        // use node specific installers, etc
        jdk = jdk.forNode(currentNode, listener);
        jdk = jdk.forEnvironment(env);

        javaExePath = jdk.getBinDir() + "/" + javaExePath;
      }

      args.add(javaExePath);

      splitAndAddArgs(jvmFlags, args);
      splitAndAddArgs(sbtFlags, args);

      args.add("-jar");

      args.add(launcherPath);

      for (String action : split(actions)) {
        args.add(action);
      }
    }

    return args;
  }
  @Override
  public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {

    EnvVars env = build.getEnvironment(listener);
    env.overrideAll(build.getBuildVariables());

    EnvVariableResolver helper = new EnvVariableResolver(build, listener);

    boolean success = true;
    System.out.println("Loading Blueprint !");

    int counter = 1;
    for (BlueprintParam param : params) {

      System.out.println("Creating package from directory : " + param.getBlueprintPath());

      // Resolve any environment variables in the parameters
      BlueprintParam fparam =
          new BlueprintParam(
              helper.replaceBuildParamWithValue(param.getServerUrl()),
              helper.replaceBuildParamWithValue(param.getUserName()),
              helper.replaceBuildParamWithValue(param.getPassword()),
              helper.replaceBuildParamWithValue(param.getTenant()),
              param.getPackageBlueprint(),
              env.get("WORKSPACE") + "/" + param.getBlueprintPath(),
              param.getOverWrite(),
              param.getPublishBlueprint(),
              param.getServiceCategory());

      final Blueprint blueprint = newBlueprint(listener.getLogger(), fparam);

      try {
        if (blueprint.Create()) {
          this.blueprintList.add(blueprint);

        } else {
          build.setResult(Result.FAILURE);
          success = false;
          break;
        }
      } catch (ArchiveException e) {
        e.printStackTrace();
      }
    }
    return success;
  }
  public boolean perform(
      final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
      throws VSphereException {

    PrintStream jLogger = listener.getLogger();
    EnvVars env;
    try {
      env = build.getEnvironment(listener);
    } catch (Exception e) {
      throw new VSphereException(e);
    }
    env.overrideAll(build.getBuildVariables());
    String expandedMemorySize = env.expand(memorySize);

    VSphereLogger.vsLogger(jLogger, "Preparing reconfigure: Memory");
    spec.setMemoryMB(Long.valueOf(expandedMemorySize));
    VSphereLogger.vsLogger(jLogger, "Finished!");
    return true;
  }
  @Override
  public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {
    EnvVars env = build.getEnvironment(listener);
    env.overrideAll(build.getBuildVariables());

    if (Computer.currentComputer() instanceof SlaveComputer) {
      FilePath destinationFilePath;
      if (isOverrideDestinationFolder() && StringUtils.isNotBlank(getDestinationFolder())) {
        destinationFilePath = new FilePath(new File(env.expand(getDestinationFolder())));
      } else {
        destinationFilePath =
            CopyToSlaveUtils.getProjectWorkspaceOnMaster(build, listener.getLogger());
      }

      FilePath projectWorkspaceOnSlave = build.getProject().getWorkspace();

      String includes = env.expand(getIncludes());
      String excludes = env.expand(getExcludes());

      listener
          .getLogger()
          .printf(
              "[copy-to-slave] Copying '%s', excluding %s, from '%s' on '%s' to '%s' on the master.\n",
              includes,
              StringUtils.isBlank(excludes) ? "nothing" : '\'' + excludes + '\'',
              projectWorkspaceOnSlave.toURI(),
              Computer.currentComputer().getNode(),
              destinationFilePath.toURI());

      projectWorkspaceOnSlave.copyRecursiveTo(includes, excludes, destinationFilePath);
    } else if (Computer.currentComputer() instanceof MasterComputer) {
      listener
          .getLogger()
          .println(
              "[copy-to-slave] The build is taking place on the master node, no copy back to the master will take place.");
    }

    return true;
  }
  /**
   * Note that with Hudson 1.341, trigger should be using {@link
   * BuildTrigger#buildDependencyGraph(AbstractProject, hudson.model.DependencyGraph)}.
   */
  public List<Future<AbstractBuild>> perform(
      AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
      throws InterruptedException, IOException {
    EnvVars env = build.getEnvironment(listener);
    env.overrideAll(build.getBuildVariables());

    try {
      if (condition.isMet(build.getResult())) {
        List<Action> actions = getBaseActions(build, listener);

        List<Future<AbstractBuild>> futures = new ArrayList<Future<AbstractBuild>>();
        for (AbstractProject project : getProjectList(env)) {
          List<Action> list = getBuildActions(actions, project);

          futures.add(schedule(build, project, list));
        }
        return futures;
      }
    } catch (DontTriggerException e) {
      // don't trigger on this configuration
    }
    return Collections.emptyList();
  }
  /* (non-Javadoc)
   * @see hudson.tasks.BuildWrapper#setUp(hudson.model.AbstractBuild, hudson.Launcher, hudson.model.BuildListener)
   */
  private boolean markVm(
      final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
      throws VSphereException {
    PrintStream jLogger = listener.getLogger();
    VSphereLogger.vsLogger(jLogger, "Converting template to VM. Please wait ...");

    EnvVars env;
    try {
      env = build.getEnvironment(listener);
    } catch (Exception e) {
      throw new VSphereException(e);
    }

    // TODO:  take in a comma delimited list and convert all
    env.overrideAll(build.getBuildVariables()); // Add in matrix axes..
    String expandedTemplate = env.expand(template);

    VirtualMachine vm = vsphere.markAsVm(expandedTemplate);
    VSphereLogger.vsLogger(jLogger, "\"" + expandedTemplate + "\" is a VM!");

    if (powerOn) {
      vsphere.startVm(expandedTemplate);
      String vmIP = vsphere.getIp(vm);
      if (vmIP != null) {
        VSphereLogger.vsLogger(jLogger, "Got IP for \"" + expandedTemplate + "\" ");
        VSphereEnvAction envAction = new VSphereEnvAction();
        envAction.add("VSPHERE_IP", vmIP);
        build.addAction(envAction);
        return true;
      }

      VSphereLogger.vsLogger(jLogger, "Error: Could not get IP for \"" + expandedTemplate + "\" ");
      return false;
    }

    return true;
  }
 public EnvVariableResolver(AbstractBuild<?, ?> build, BuildListener listener)
     throws IOException, InterruptedException {
   environment = build.getEnvironment(listener);
   environment.overrideAll(build.getBuildVariables());
 }
  @Override
  public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener)
      throws IOException, InterruptedException {

    EnvVars env = build.getEnvironment(listener);
    env.overrideAll(build.getBuildVariables());
    EnvVariableResolver helper = new EnvVariableResolver(build, listener);

    boolean success = true;

    int counter = 1;
    for (PluginParam param : params) {

      // resolve build vars in request params
      List<RequestParam> rparamResolved = new ArrayList<RequestParam>();
      ;

      for (RequestParam rparam : param.getRequestParams()) {
        String rparamString =
            helper.replaceBuildParamWithValue(rparam.getRequestParam().toString());
        rparamResolved.add(new RequestParam(rparamString));
      }

      // Resolve any environment variables in the parameters
      PluginParam fparam =
          new PluginParam(
              helper.replaceBuildParamWithValue(param.getServerUrl()),
              helper.replaceBuildParamWithValue(param.getUserName()),
              helper.replaceBuildParamWithValue(param.getPassword()),
              helper.replaceBuildParamWithValue(param.getTenant()),
              helper.replaceBuildParamWithValue(param.getBluePrintName()),
              param.isWaitExec(),
              param.getRequestTemplate(),
              rparamResolved);

      final Deployment deployment = newDeployment(listener.getLogger(), fparam);

      if (deployment.Create()) {
        this.deployments.add(deployment);
        // change counter to string and append be for build environment
        String strCounter = Integer.toString(counter) + "be";
        env.putAll(deployment.getDeploymentComponents(strCounter));
        counter++;
      } else {
        build.setResult(Result.FAILURE);
        success = false;
        break;
      }

      if (!success) {
        doTearDown();
        return null;
      }
    }
    return new Environment() {
      @Override
      public boolean tearDown(AbstractBuild build, BuildListener listener)
          throws IOException, InterruptedException {

        return doTearDown();
      }
    };
  }