Skip to content

Commit

Permalink
Merge pull request #18 from alexouzounis/JENKINS-24735
Browse files Browse the repository at this point in the history
JENKINS-24735 - Add support for build parameters in Subversion URLs
  • Loading branch information
hugueschabot committed Nov 3, 2014
2 parents d845cf0 + 8e1a3b7 commit 344a848
Showing 1 changed file with 69 additions and 56 deletions.
125 changes: 69 additions & 56 deletions 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 344a848

Please sign in to comment.