-
Improvement
-
Resolution: Fixed
-
Major
-
None
First I fixed the recursive mkdirs bug that was reported for this scp plugin.
With my fix the workspace can be copied to an other computer over ssh and all the directory structure will be created.
The improvement:
I had the need to be able to use the node properties env vars in the plugin .
So for example we needed to build the same project on a different hardware and OS.
Like Solaris SPARC, AIX, HPUX, Windows and so on.
So in the node properties env vars we set variables for identifying which is the computer and the OS version/platform and others.
Those environment variables we needed to use in the plugin so we can know which project was build successful or failed or any
other problems.
Here is the code changes I made to work as I needed:
The changes was only in class
be/certipost/hudson/plugin/SCPRepositoryPublisher.java
I added a method:
/**
- Returns the environment variables set for a node/slave. So you can use
- them, as are in your environment
- @param envVars
- @return
*/
public static EnvVars getEnvVars() {
Node node = Computer.currentComputer().getNode();
DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node
.getNodeProperties();
if (Computer.currentComputer() instanceof MasterComputer)
{ Hudson instance = Hudson.getInstance(); nodeProperties=instance.getGlobalNodeProperties(); } Iterator<NodeProperty<?>> iterator = nodeProperties.iterator();
while (iterator.hasNext()) {
NodeProperty<?> next = iterator.next();
if (next instanceof EnvironmentVariablesNodeProperty)
}
return null;
}
and changed the method perform :
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
.........................
.........................
Map<String, String> envVars = build.getEnvVars();
// Patched for env vars
EnvVars objNodeEnvVars = getEnvVars();
if (objNodeEnvVars != null)
//~ Patched for env vars
for (Entry e : entries) {
String expanded = Util.replaceMacro(e.sourceFile, envVars);
FilePath ws = build.getProject().getWorkspace();
FilePath[] src = ws.list(expanded);
if (src.length == 0)
String folderPath = Util.replaceMacro(e.filePath, envVars);
// Fix for recursive mkdirs
String strWorkspacePath = ws.toString();
envVars.put("strWorkspacePath", strWorkspacePath);
// ~Fix for recursive mkdirs
I also changed the class be/certipost/hudson/plugin/SCPSite.java
I added the method extractRelativePath:
/**
- Returns the relative path to the workspace
- @param strWorkspacePath
- @param filePath
- @return
*/
private String extractRelativePath(String strWorkspacePath, FilePath filePath)Unknown macro: { String strRet=""; String strFilePath=filePath.toString(); if(strWorkspacePath.length() == strFilePath.length()) { return ""; } int indexOf = strFilePath.indexOf(strWorkspacePath); if(indexOf>=0) { strRet=strFilePath.substring(strWorkspacePath.length()+1,strFilePath.length());//Exclude first file separator } indexOf = strRet.lastIndexOf(File.separator); if(indexOf>0) { strRet=strRet.substring(0,indexOf); } strRet=strRet.replace((CharSequence) "\", (CharSequence)"/"); return strRet; }
I changed the upload method to became:
public void upload(String folderPath, FilePath filePath,
Map<String, String> envVars, PrintStream logger)
throws IOException, InterruptedException, SftpException {
if (session == null || channel == null)
SftpATTRS rootdirstat = channel.stat(rootRepositoryPath);
if (rootdirstat == null)
else {
if (!rootdirstat.isDir())
}
if (filePath.isDirectory()) {
FilePath[] subfiles = filePath.list("*/");
if (subfiles != null) {
for (int i = 0; i < subfiles.length; i++)
}
} else {
String strWorkspacePath = envVars.get("strWorkspacePath");
String localfilename = filePath.getName();
mkdirs(folderPath, logger);
InputStream in = filePath.read();
String strRelativePath=extractRelativePath(strWorkspacePath , filePath);
String strTmp = folderPath + "/" +strRelativePath;
String strNewPath = rootRepositoryPath + "/" + strTmp;
if(!strRelativePath.equals(""))
String strNewFilename = strNewPath + localfilename;
channel.put(in, strNewFilename);
in.close();
}
}
- is blocking
-
JENKINS-1965 SCP upload flattens subdirectories
- Closed
- is related to
-
JENKINS-8170 SCP plugin 1.7 breaks paths
- Closed