Skip to content

Commit

Permalink
[FIXED JENKINS-20427] [FIXED JENKINS-14276] expanded vars in branch s…
Browse files Browse the repository at this point in the history
…pec for remote polling
  • Loading branch information
ndeloof authored and MarkEWaite committed Nov 21, 2014
1 parent fe43851 commit 75e4e6c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/hudson/plugins/git/GitSCM.java
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)) {
Expand Down

3 comments on commit 75e4e6c

@nhanda03
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@nhanda03
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.