Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-24735 - Add support for build parameters in Subversion URLs
* Add support for Global Node Properties as well
- Loading branch information
1 parent
c1c458c
commit 8e1a3b7
Showing
1 changed file
with
69 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} |