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

[JENKINS-33016] Jenkins doesn't detect CVS polling on Pipeline (Workflow) Job #50

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
44 changes: 41 additions & 3 deletions src/main/java/hudson/scm/AbstractCvs.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.BuildListener;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -477,8 +478,8 @@ public SCMRevisionState calcRevisionsFromBuild(final AbstractBuild<?, ?> build,

@Override
public @CheckForNull SCMRevisionState calcRevisionsFromBuild(@Nonnull Run<?,?> build, @Nullable FilePath workspace,
@Nullable Launcher launcher, @Nonnull TaskListener listener)
throws IOException, InterruptedException {
@Nullable Launcher launcher, @Nonnull TaskListener listener)
throws IOException, InterruptedException {
return build.getAction(CvsRevisionState.class);
}

Expand All @@ -503,6 +504,43 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> pr

final EnvVars envVars = project.getLastBuild().getEnvironment(listener);

return worker_compareRemoteRevisionWith(envVars, build.getTime(), launcher, workspace, listener, baseline, repositories);

}

protected PollingResult compareRemoteRevisionWith(final Job<?, ?> project, final Launcher launcher,
final FilePath workspace, final TaskListener listener,
final SCMRevisionState baseline, final CvsRepository[] repositories)
throws IOException, InterruptedException {

Run<?, ?> build = project.getLastBuild();

// No previous build? everything has changed
if (null == build) {
listener.getLogger().println("No previous build found, scheduling build");
return PollingResult.BUILD_NOW;
}

if (build instanceof AbstractBuild<?, ?> && !((AbstractBuild<?, ?>) build).hasChangeSetComputed() && build.isBuilding()) {
listener.getLogger().println("Previous build has not finished checkout."
+ " Not triggering build as no valid baseline comparison available.");
return PollingResult.NO_CHANGES;
}

final EnvVars envVars = build.getEnvironment(listener);

return worker_compareRemoteRevisionWith(envVars, build.getTime(), launcher, workspace, listener, baseline, repositories);

}


protected PollingResult worker_compareRemoteRevisionWith(final EnvVars envVars, final Date buildTime,
final Launcher launcher,
final FilePath workspace, final TaskListener listener,
final SCMRevisionState baseline, final CvsRepository[] repositories)
throws IOException, InterruptedException {


final Date currentPollDate = Calendar.getInstance().getTime();

/*
Expand Down Expand Up @@ -537,7 +575,7 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> pr
}

// get the list of current changed files in this repository
final List<CvsFile> changes = calculateRepositoryState(build.getTime(),
final List<CvsFile> changes = calculateRepositoryState(buildTime,
currentPollDate, repository, listener, envVars, workspace);

final List<CvsFile> remoteFiles = remoteState.get(repository);
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/hudson/scm/CVSSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@ protected PollingResult compareRemoteRevisionWith(final AbstractProject<?, ?> pr
return super.compareRemoteRevisionWith(project, launcher, workspace, listener, baseline, getRepositories());
}

/**
* Checks for differences between the current workspace and the remote
* repository.
*
* @see SCM#compareRemoteRevisionWith(Job, Launcher, FilePath, TaskListener, SCMRevisionState)
*/
@Override
public PollingResult compareRemoteRevisionWith(final Job<?, ?> project, final Launcher launcher,
final FilePath workspace, final TaskListener listener, final SCMRevisionState baseline)
throws IOException, InterruptedException {

return super.compareRemoteRevisionWith(project, launcher, workspace, listener, baseline, getRepositories());
}

/**
* If there are multiple modules, return the module directory of the first
* one.
Expand Down
27 changes: 18 additions & 9 deletions src/main/java/hudson/scm/CvsProjectset.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,33 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,
listener, baseline, getAllRepositories(workspace));
}

@Override
public PollingResult compareRemoteRevisionWith(Job<?, ?> project, Launcher launcher,
FilePath workspace, TaskListener listener,
SCMRevisionState baseline)
throws IOException, InterruptedException {
return super.compareRemoteRevisionWith(project, launcher, workspace,
listener, baseline, getAllRepositories(workspace));
}

@Override
public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace, BuildListener listener,
File changelogFile) throws IOException, InterruptedException {
try {
checkout(build, launcher, workspace, listener, changelogFile, null);
}
catch (AbortException e) {
return false;
}
try {
checkout(build, launcher, workspace, listener, changelogFile, null);
}
catch (AbortException e) {
return false;
}
return true;
}


@Override
public void checkout(final @Nonnull Run<?,?> build, final @Nonnull Launcher launcher, final @Nonnull FilePath workspace,
final @Nonnull TaskListener listener, final @CheckForNull File changelogFile,
final @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException {
final @Nonnull TaskListener listener, final @CheckForNull File changelogFile,
final @CheckForNull SCMRevisionState baseline) throws IOException, InterruptedException {
if (!isCanUseUpdate()) {
workspace.deleteContents();
}
Expand Down