Skip to content
Permalink
Browse files
JENKINS-24735 - Add support for build parameters in Subversion URLs
 
 * Add support for Global Node Properties as well
  • Loading branch information
alexouzounis committed Nov 2, 2014
1 parent c1c458c commit 8e1a3b75d19221d1dd2c2edffac35fb23640b2ba
Showing with 69 additions and 56 deletions.
  1. +69 −56 src/main/java/jenkins/plugins/svnmerge/Utility.java
@@ -1,56 +1,69 @@
package jenkins.plugins.svnmerge;

import hudson.EnvVars;
import hudson.model.Computer;
import hudson.model.Job;
import hudson.scm.SubversionSCM.ModuleLocation;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Utility {


/**
* Expands the system variables, the node environment variables and the project parameters
*/
public static ModuleLocation getExpandedLocation(ModuleLocation ml, Job<?,?> project) {
ModuleLocation location= ml.getExpandedLocation(project);
// expand system variables
Computer c = Computer.currentComputer();
if (c != null) {
try {
// JVM vars
EnvVars cEnv = c.getEnvironment();
location = location.getExpandedLocation(cEnv);
// node vars
for (NodeProperty<?> nodeProp : c.getNode().getNodeProperties()) {
if (nodeProp instanceof EnvironmentVariablesNodeProperty) {
EnvVars nodeEnvVars = ((EnvironmentVariablesNodeProperty) nodeProp)
.getEnvVars();
location = location
.getExpandedLocation(nodeEnvVars);

}
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",
e);
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",
e);

}
}
// expand project variables
if(project!=null){
location = location.getExpandedLocation(project);
}
return location;
}

private static final Logger LOGGER = Logger.getLogger(Utility.class.getName());
}
package jenkins.plugins.svnmerge;

import hudson.EnvVars;
import hudson.model.Computer;
import hudson.model.Job;
import hudson.scm.SubversionSCM.ModuleLocation;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import jenkins.model.Jenkins;

public class Utility {


/**
* Expands the system variables, the node environment variables and the project parameters
*/
public static ModuleLocation getExpandedLocation(ModuleLocation ml, Job<?,?> project) {
ModuleLocation location= ml.getExpandedLocation(project);
// expand system variables
Computer c = Computer.currentComputer();
if (c != null) {
try {
// JVM vars
EnvVars cEnv = c.getEnvironment();
location = location.getExpandedLocation(cEnv);
// global node vars
for (NodeProperty<?> globalNodeProp : Jenkins.getInstance().getGlobalNodeProperties()) {
if (globalNodeProp instanceof EnvironmentVariablesNodeProperty) {
EnvVars nodeEnvVars = ((EnvironmentVariablesNodeProperty) globalNodeProp)
.getEnvVars();
location = location
.getExpandedLocation(nodeEnvVars);

}
}

// node vars
for (NodeProperty<?> nodeProp : c.getNode().getNodeProperties()) {
if (nodeProp instanceof EnvironmentVariablesNodeProperty) {
EnvVars nodeEnvVars = ((EnvironmentVariablesNodeProperty) nodeProp)
.getEnvVars();
location = location
.getExpandedLocation(nodeEnvVars);

}
}
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",
e);
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to get computer environment",
e);

}
}
// expand project variables
if(project!=null){
location = location.getExpandedLocation(project);
}
return location;
}

private static final Logger LOGGER = Logger.getLogger(Utility.class.getName());
}

0 comments on commit 8e1a3b7

Please sign in to comment.