Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIXED JENKINS-17913] Expand manifest file and URL #21

Merged
merged 1 commit into from
Oct 26, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions src/main/java/hudson/plugins/repo/RepoScm.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,14 @@ public String getManifestBranch() {
return manifestBranch;
}

private String getManifestBranch(final EnvVars env) {
return manifestBranch == null ? null : env.expand(manifestBranch);
}

/**
* Same as {@link #getManifestBranch()} but with <em>default</em>
* values of parameters expanded.
* @param environment an existing environment, which contains already
* properties from the current build
* @param project the project that is being built
*/
private String getManifestBranchExpanded(final EnvVars environment,
private EnvVars getEnvVars(final EnvVars environment,
final AbstractProject<?, ?> project) {
// create an empty vars map
final EnvVars finalEnv = new EnvVars();
Expand All @@ -144,8 +140,7 @@ private String getManifestBranchExpanded(final EnvVars environment,
}

EnvVars.resolve(finalEnv);

return getManifestBranch(finalEnv);
return finalEnv;
}

/**
Expand Down Expand Up @@ -174,6 +169,7 @@ public String getManifestGroup() {
public String getRepoUrl() {
return repoUrl;
}

/**
* Returns the name of the mirror directory. By default, this is null and
* repo does not use a mirror.
Expand Down Expand Up @@ -329,8 +325,8 @@ protected PollingResult compareRemoteRevisionWith(
final SCMRevisionState baseline) throws IOException,
InterruptedException {
SCMRevisionState myBaseline = baseline;
final String expandedManifestBranch =
getManifestBranchExpanded(null, project);
final EnvVars env = getEnvVars(null, project);
final String expandedManifestBranch = env.expand(manifestBranch);
final AbstractBuild<?, ?> lastBuild = project.getLastBuild();

if (myBaseline == null) {
Expand All @@ -351,8 +347,7 @@ protected PollingResult compareRemoteRevisionWith(
repoDir = workspace;
}

if (!checkoutCode(launcher, repoDir, expandedManifestBranch,
listener.getLogger())) {
if (!checkoutCode(launcher, repoDir, env, listener.getLogger())) {
// Some error occurred, try a build now so it gets logged.
return new PollingResult(myBaseline, myBaseline,
Change.INCOMPARABLE);
Expand Down Expand Up @@ -388,17 +383,17 @@ public boolean checkout(
repoDir = workspace;
}

AbstractProject<?, ?> proj = build.getProject();
EnvVars env = build.getEnvironment(listener);
final String expandedBranch = getManifestBranchExpanded(
env, build.getProject());
if (!checkoutCode(launcher, repoDir, expandedBranch,
listener.getLogger())) {
env = getEnvVars(env, proj);
if (!checkoutCode(launcher, repoDir, env, listener.getLogger())) {
return false;
}
final String manifest =
getStaticManifest(launcher, repoDir, listener.getLogger());
final String manifestRevision =
getManifestRevision(launcher, repoDir, listener.getLogger());
final String expandedBranch = env.expand(manifestBranch);
final RevisionState currentState =
new RevisionState(manifest, manifestRevision, expandedBranch,
listener.getLogger());
Expand Down Expand Up @@ -452,7 +447,8 @@ private int doSync(final Launcher launcher, final FilePath workspace,
}

private boolean checkoutCode(final Launcher launcher,
final FilePath workspace, final String expandedManifestBranch,
final FilePath workspace,
final EnvVars env,
final OutputStream logger)
throws IOException, InterruptedException {
final List<String> commands = new ArrayList<String>(4);
Expand All @@ -462,25 +458,25 @@ private boolean checkoutCode(final Launcher launcher,
commands.add(getDescriptor().getExecutable());
commands.add("init");
commands.add("-u");
commands.add(manifestRepositoryUrl);
if (expandedManifestBranch != null) {
commands.add(env.expand(manifestRepositoryUrl));
if (manifestBranch != null) {
commands.add("-b");
commands.add(expandedManifestBranch);
commands.add(env.expand(manifestBranch));
}
if (manifestFile != null) {
commands.add("-m");
commands.add(manifestFile);
commands.add(env.expand(manifestFile));
}
if (mirrorDir != null) {
commands.add("--reference=" + mirrorDir);
commands.add("--reference=" + env.expand(mirrorDir));
}
if (repoUrl != null) {
commands.add("--repo-url=" + repoUrl);
commands.add("--repo-url=" + env.expand(repoUrl));
commands.add("--no-repo-verify");
}
if (manifestGroup != null) {
commands.add("-g");
commands.add(manifestGroup);
commands.add(env.expand(manifestGroup));
}
if (depth != 0) {
commands.add("--depth=" + depth);
Expand Down