Skip to content
Permalink
Browse files

[FIXED JENKINS-20427] [FIXED JENKINS-14276] expanded vars in branch s…

…pec for remote polling
  • Loading branch information...
ndeloof authored and MarkEWaite committed Sep 24, 2014
1 parent fe43851 commit 75e4e6c2282e069bd26fbce0ead19c1c5b722c04
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/main/java/hudson/plugins/git/GitSCM.java
@@ -506,6 +506,7 @@ public boolean requiresWorkspaceForPolling() {
for (GitSCMExtension ext : getExtensions()) {
if (ext.requiresWorkspaceForPolling()) return true;
}
// TODO would need to use hudson.plugins.git.util.GitUtils.getPollEnvironment
return getSingleBranch(new EnvVars()) == null;
}

@@ -553,16 +554,17 @@ private PollingResult compareRemoteRevisionWithImpl(Job<?, ?> project, Launcher
final String singleBranch = getSingleBranch(lastBuild.getEnvironment(listener));

// fast remote polling needs a single branch and an existing last build
if (!requiresWorkspaceForPolling() && buildData.lastBuild != null && buildData.lastBuild.getMarked() != null) {

// FIXME this should not be a specific case, but have BuildChooser tell us if it can poll without workspace.
if (singleBranch != null // branch spec can be resolved to a single branch
&& buildData.lastBuild != null && buildData.lastBuild.getMarked() != null // we know previous build commit
&& !requiresWorkspaceForPolling() // remote polling hasn't been intentionally disabled
) {

final EnvVars environment = project instanceof AbstractProject ? GitUtils.getPollEnvironment((AbstractProject) project, workspace, launcher, listener, false) : new EnvVars();

GitClient git = createClient(listener, environment, project, Jenkins.getInstance(), null);

String gitRepo = getParamExpandedRepos(lastBuild, listener).get(0).getURIs().get(0).toString();
ObjectId head = git.getHeadRev(gitRepo, getBranches().get(0).getName());
ObjectId head = git.getHeadRev(gitRepo, singleBranch);
if (head != null){
listener.getLogger().println("[poll] Latest remote head revision is: " + head.getName());
if (buildData.lastBuild.getMarked().getSha1().equals(head)) {

3 comments on commit 75e4e6c

@max-10001

This comment has been minimized.

Copy link

replied Apr 26, 2016

I'm on git-2.5.0-beta5 and my scm polling still doesn't work if I parameterize branch with an environment variable. Any clues?

@MarkEWaite

This comment has been minimized.

Copy link

replied Apr 26, 2016

I need more information on what precisely you're expecting from a branch name that includes an environment variable. I don't understand your "still doesn't work" comment.

Are you expecting that it will take the value of the environment variable from the Jenkins master process?

Should it take the value of the environment variable from the last run of the job?

@max-10001

This comment has been minimized.

Copy link

replied Apr 26, 2016

branch name in my case is coming from env variable defined at pipeline level. And scm polling job is part of that pipeline. The polling just doesn't pick the changes if I use variable which is an environment variable coming from pipeline level in branch spec. Just for the same of testing I included a parameter in the job and when used that in branch spec the scm polling works, so somehow the problem is only with the environment variable coming from pipeline level.

Please sign in to comment.
You can’t perform that action at this time.