rlalyko
I'm new here

Windows Deployment by RoboCopy

Environment: Windows 7, Firstspirit 5.2

If you like to deploy the firstspirit HTL generate by MS Windows commandline here's a robocopy example script.

Steps to implement:

- Create a new action (script)

- Copy the script lines (provided in this task) into the new action script

- Create the targetpath parameter for the new script (the path to copy the html generate)

// #########################################################

//

// RoboCopy - Bean Shell Script

//

import de.espirit.firstspirit.agency.ProcessAgent;

import java.util.List;

import java.util.ArrayList;

targetpath     =  " C:\\Import\\lpi-deployments";

// end of variable definition

tasklist = context.getTasks();

t = context.getTask();

s = t.getScheduleEntry();

p = s.getProject();

srcpath = context.getPath();

log = "Windows-Local-Deployment for project \"" + p.getName() + "\": ";

context.logInfo(log + "script started");

params = t.getParameters();

if (params == null) {

          context.logError(log + " failed. Missing parameters. "

                    + "Required: targetpath" );

          return;

}

for(pa: params) {

          switch(pa.getKey()) {

          case "targetpath":

                    targetpath = pa.getValue();

                    break;

          }

}

List<String> commandList = new ArrayList<String>();

commandList.add( "cmd" );

commandList.add( "/c" );

commandList.add( "ROBOCOPY " + srcpath.replace("/", "\\") + " " +  targetpath.replace("/", "\\") + " /MIR");

Process process=null;

       try {

            ProcessBuilder pb = new ProcessBuilder(commandList);

            pb.redirectErrorStream(true);

            context.logInfo("START ROBOCOPY  from: " + srcpath + "  to: " + targetpath);

          

            process=pb.start();

            BufferedReader inStreamReader = new BufferedReader(

                new InputStreamReader(process.getInputStream()));

            String line = null;

            while( (line=inStreamReader.readLine()) != null){

                 context.logInfo(line);

            }

            result = process.waitFor();

            if ( ( result == 0 ) || ( result == 1 ) ) {

                context.logInfo(log + "command completed");

            } else {

                context.logError(log + "failed with exitcode " + result + " for " + command);

            }

      } catch (InterruptedException e) {

            context.logError(log + "interrupted, for " + command);

      } catch (Exception e) {

            context.logError(log + "failed for " + command + " - " + e);

      } finally {

            if (process != null) {

                  process.destroy();

           }

     }

context.logInfo(log + "script completed");

// #########################################################

0 Kudos
1 Reply
pavone
I'm new here

Re: Windows Deployment by RoboCopy

Hi Robert,

thanks for sharing this script! Smiley Happy Tip: To share things like that you can also create a blog posting.

Best regards

Tim

0 Kudos