Skip to content

Commit

Permalink
JENKINS-10073: Set ACCUREV_STREAM by parameter
Browse files Browse the repository at this point in the history
An external entity provides the stream which the AccuRev plugin would use.

For example there is a parametrized job which's string parameter gets the name that the plugin should use.

Otherwise, an overwrite of %ACCUREV_STREAM% (e.g. set a parameter called ACCUREV_STREAM) would be an alternative.

It should be done like the "Build selector for Copy Artifact" which can be set as a parameter and the plugin is able to retrieve the value from this special parameter.

See: https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin

-----------

files contain fix to this improvement
usage:

*	make parameter in job e.g. acstream
*	then set in stream name field: ${acstream}
*	SCM polling will go against the default value of the parameter

One thing what we didn’t put in there is the catch of Choice parameters for the SCM polling since we were happy with the simple String parameter.

Signed-off-by: helterscelter <https://github.com/helterscelter>
  • Loading branch information
robsimon authored and helterscelter committed Jul 12, 2011
1 parent 3e0e22c commit 5963a90
Showing 1 changed file with 79 additions and 11 deletions.
90 changes: 79 additions & 11 deletions src/main/java/hudson/plugins/accurev/AccurevSCM.java
Expand Up @@ -18,6 +18,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -39,6 +40,10 @@
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.ModelObject;
import hudson.model.ParameterValue;
import hudson.model.StringParameterValue;
import hudson.model.ParameterDefinition;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -355,11 +360,19 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
listener.fatalError("Must specify a depot");
return false;
}



if (stream == null || "".equals(stream)) {
listener.fatalError("Must specify a stream");
return false;
}
if (streams != null && !streams.containsKey(stream)) {

EnvVars environment = build.getEnvironment(listener);

String localStream = environment.expand(stream);

if (streams != null && !streams.containsKey(localStream)) {
listener.fatalError("The specified stream does not appear to exist!");
return false;
}
Expand Down Expand Up @@ -412,11 +425,11 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
cmd.add("-w");
cmd.add(this.workspace);

if (!stream.equals(accurevWorkspace.getStream().getParent().getName())) {
if (!localStream.equals(accurevWorkspace.getStream().getParent().getName())) {
listener.getLogger().println("Parent stream needs to be updated.");
needsRelocation = true;
cmd.add("-b");
cmd.add(this.stream);
cmd.add(localStream);
}
if (!accurevWorkspace.getHost().equals(remoteDetails.getHostName())) {
listener.getLogger().println("Host needs to be updated.");
Expand All @@ -442,7 +455,7 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
listener.getLogger().println(" New storage: " + remoteDetails.getPath());
listener.getLogger().println(" Old parent stream: " + accurevWorkspace.getStream().getParent()
.getName());
listener.getLogger().println(" New parent stream: " + stream);
listener.getLogger().println(" New parent stream: " + localStream);
listener.getLogger().println(cmd.toStringWithQuote());

final int rv;
Expand Down Expand Up @@ -506,7 +519,7 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
cmd.add("-s");
cmd.add(snapshotName);
cmd.add("-b");
cmd.add(stream);
cmd.add(localStream);
cmd.add("-t");
cmd.add("now");
int rv;
Expand Down Expand Up @@ -545,7 +558,7 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
cmd.add("pop");
addServer(cmd, server);
cmd.add("-v");
cmd.add(stream);
cmd.add(localStream);
cmd.add("-L");
cmd.add(workspace.getRemote());
cmd.add("-R");
Expand Down Expand Up @@ -574,13 +587,13 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
}

{
AccurevStream stream = streams == null ? null : streams.get(this.stream);
AccurevStream stream = streams == null ? null : streams.get(localStream);

if (stream == null) {
// if there was a problem, fall back to simple stream check
return captureChangelog(server, accurevEnv, workspace, listener, accurevPath, launcher,
startDateOfPopulate, startTime == null ? null : startTime.getTime(),
this.stream, changelogFile);
localStream, changelogFile);
}
// There may be changes in a parent stream that we need to factor in.
// TODO produce a consolidated list of changes from the parent streams
Expand All @@ -596,7 +609,7 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
} while (stream != null && stream.isReceivingChangesFromParent());
}
return captureChangelog(server, accurevEnv, workspace, listener, accurevPath, launcher,
startDateOfPopulate, startTime == null ? null : startTime.getTime(), this.stream,
startDateOfPopulate, startTime == null ? null : startTime.getTime(), localStream,
changelogFile);
}

Expand Down Expand Up @@ -724,6 +737,10 @@ private boolean captureChangelog(AccurevServer server,
public ChangeLogParser createChangeLogParser() {
return new AccurevChangeLogParser();
}

private static boolean hasStringVariableReference(final String str) {
return str != null && str.indexOf("${") != -1;
}

/**
* {@inheritDoc}
Expand Down Expand Up @@ -761,12 +778,63 @@ public boolean pollChanges(AbstractProject project, Launcher launcher, FilePath
listener.getLogger().println("Last build on " + buildDate);

final Map<String, AccurevStream> streams = getStreams(server, accurevEnv, workspace, listener, accurevPath, launcher);

EnvVars environment = null;

if(hasStringVariableReference(this.stream)){
ParametersDefinitionProperty paramDefProp = (ParametersDefinitionProperty) project.getProperty(ParametersDefinitionProperty.class);

if(paramDefProp == null) {
listener.getLogger().println("Polling is not supported when stream name has a variable reference '" + this.stream + "'.");

// as we don't know which stream to check we just state that there is no changes
return false;
}

listener.getLogger().println("logout of parameter definitions ...");

Map<String, String> keyValues = new TreeMap<String, String>();

/* Scan for all parameter with an associated default values */
for(ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions())
{
//listener.getLogger().println("parameter definition for '" + paramDefinition.getName() + "':");

ParameterValue defaultValue = paramDefinition.getDefaultParameterValue();

if(defaultValue instanceof StringParameterValue){
StringParameterValue strdefvalue = (StringParameterValue) defaultValue;

//listener.getLogger().println("parameter default value for '" + defaultValue.getName() + " / " + defaultValue.getDescription() + "' is '" + strdefvalue.value + "'.");

keyValues.put(defaultValue.getName(), strdefvalue.value);
}
}

environment = new EnvVars(keyValues);
}

if(environment == null){
return false;
}

String localStream = environment.expand(this.stream);

if(hasStringVariableReference(localStream)){
listener.getLogger().println("Polling is not supported when stream name has a variable reference '" + this.stream + "'.");

// as we don't know which stream to check we just state that there is no changes
return false;
}


listener.getLogger().println("... expanded '" + this.stream + "' to '" + localStream + "'.");

AccurevStream stream = streams == null ? null : streams.get(this.stream);
AccurevStream stream = streams == null ? null : streams.get(localStream);

if (stream == null) {
// if there was a problem, fall back to simple stream check
return checkStreamForChanges(server, accurevEnv, workspace, listener, accurevPath, launcher, this.stream,
return checkStreamForChanges(server, accurevEnv, workspace, listener, accurevPath, launcher,localStream,
buildDate);
}
// There may be changes in a parent stream that we need to factor in.
Expand Down

0 comments on commit 5963a90

Please sign in to comment.