Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Hot to copy published artifacts from server to build agent #2736

bobv ·
Our developers want to copy one of the published artifacts from another build (more precisely, the latest successful build of another configuration) to their workspace directory on the build agent, so they can package it into their setup program.
I have written a script, see below, but the scp command doesn't work because our server is Windows. Is there another way using a 'QuickBuild only' method to do this?

groovy:
// Find artifacts directory
fromURL = grid.getServerNode().getHostName() + ":" + system.getConfiguration("root/Products/MyProduct").getLatestSuccessfulBuild().getArtifactsDir();
logger.info("Location of latest succesful build of UI: " + fromURL);
toDir = build.configuration.getWorkspaceDir() + "/build/win_release";
logger.info("Local output directory: " + toDir);

// Copy the zip file
command = "scp " + fromURL + "/windows/Product.zip " + toDir + "\windows";
proc = command.execute();
proc.waitFor();
result = proc.exitValue();
if (result != 0) {
throw new com.pmease.quickbuild.QuickbuildException("Failed to copy artifacts: " + proc.err.text);
logger.error("Failed to copy artifacts: " + proc.err.text);
} else {
logger.info("Copied artifacts to " + toDir);
}
  • replies 3
  • views 2715
  • stars 0
robinshen ADMIN ·
Please use below script to transfer file with QB file transferring API:

groovy:
def fromBuild = system.getConfiguration("root/Products/MyProduct").getLatestSuccessfulBuild();
def toFile = build.configuration.getWorkspaceDir() + "/build/win_release/Product.zip";
grid.transferFile(grid.serverNode, system.serverService.getBuildPublishDir(fromBuild.id) + "/artifacts/windows/Product.zip",
grid.localNode, toFile, null, null);
bobv ·
Hi Robin,

Thanks for your support. I have used your input to arrive at the following code:

groovy:
// Copy the zip file
def fromBuild = system.getConfiguration("root/Products/MyProduct").getLatestSuccessfulBuild();
logger.info("Latest succesful build: " + fromBuild);
def fromDir = system.serverService.getBuildPublishDir(fromBuild.id);
def fromFile = fromDir.replace('\', '/') + "/artifacts/windows/ProductFiles_*.zip"; // Note the wildcard that I need to use. However, I get the same error without wildcard
logger.info("Source files: " + fromFile);
def toFile = build.configuration.getWorkspaceDir().getPath().replace('\', '/') + "/build/win_release/";
logger.info("Destination directory: " + toFile);
grid.transferFile(grid.serverNode, fromFile, grid.localNode, toFile, null, null);

Unfortunately I get an HTTP 500 error:
Step 'master>Build>CopyUItoResults' is failed: java.lang.RuntimeException: java.io.IOException: Server returned HTTP response code: 500 for URL: https://cvl-bld-502/file_transfer?file= ... iles_*.zip

When I paste the URL into a browser I get an HTTP 500 Access denied for connection error. Any ideas how to fix this?

Bob
robinshen ADMIN ·
Please use grid.transferFiles API to transfer files with defined patterns, as demonstrated below.

groovy:
// Copy the zip file
def fromBuild = system.getConfiguration("root/Products/MyProduct").getLatestSuccessfulBuild();
logger.info("Latest succesful build: " + fromBuild);
def fromDir = system.serverService.getBuildPublishDir(fromBuild.id).replace('\', '/') + "/artifacts/windows";
def fromPattern = "ProductFiles_*.zip";
logger.info("Source dir: " + fromDir);
logger.info("Source pattern: " + fromPattern);
def toDir = build.configuration.getWorkspaceDir().getAbsolutePath().replace('\', '/') + "/build/win_release/";
logger.info("Destination directory: " + toFile);
grid.transferFiles(grid.serverNode, fromDir, fromPattern, grid.localNode, toDir, false, null, null);


If this still does not work, please check the server console log to see what server complains.