Skip to content

Commit

Permalink
jenkinsci#234: Do not require a workspace to notify Bitbucket
Browse files Browse the repository at this point in the history
Historically, the stashNotifier plugin required a workspace
context in order to perform the plugin task, albeit not
making use of the workspace in any way.

This change removes the implementation of the perform
method requiring a workspace and replaces it with the
one not requiring a workspace.
  • Loading branch information
nathanhi committed Dec 9, 2024
1 parent 6d49910 commit 89b23bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.FilePath;
import hudson.EnvVars;
import hudson.Launcher;
import hudson.ProxyConfiguration;
import hudson.model.*;
Expand Down Expand Up @@ -361,26 +362,29 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
return disableInprogressNotification || processJenkinsEvent(build, null, listener, StashBuildState.INPROGRESS);
}

@Override
public boolean requiresWorkspace() {
return false;
}

@Override
public boolean perform(
AbstractBuild<?, ?> build,
Launcher launcher,
BuildListener listener) {
return perform(build, null, listener, disableInprogressNotification);
return perform(build, listener, disableInprogressNotification);
}

@Override
public void perform(@NonNull Run<?, ?> run,
@NonNull FilePath workspace,
@NonNull Launcher launcher,
@NonNull EnvVars env,
@NonNull TaskListener listener) {
if (!perform(run, workspace, listener, false)) {
if (!perform(run, listener, false)) {
run.setResult(Result.FAILURE);
}
}

private boolean perform(Run<?, ?> run,
FilePath workspace,
TaskListener listener,
boolean disableInProgress) {
StashBuildState state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ private StashNotifier buildStashNotifier(String stashBaseUrl,
private static BuildListener buildListener;
private static AbstractBuild<?, ?> build;
private static Run<?, ?> run;
private static FilePath workspace;

@BeforeClass
public static void setUp() throws Exception {
Expand All @@ -131,7 +130,6 @@ public static void setUp() throws Exception {
when(file.getPath()).thenReturn("/tmp/fake/path");
FilePath filePath = new FilePath(file);
when(project.getSomeWorkspace()).thenReturn(filePath);
workspace = project.getSomeWorkspace();
EnvVars environment = mock(EnvVars.class);
PrintStream logger = System.out;
Secret secret = mock(Secret.class);
Expand Down Expand Up @@ -295,7 +293,7 @@ private void test_perform_simplebuildstep(Result result,
Launcher launcher = test_perform(result, logger, notificationResult, hashes);

//when
sn.perform(build, workspace, launcher, buildListener);
sn.perform(build, launcher, buildListener);

//then
assertThat(build.getResult(), is(result));
Expand Down Expand Up @@ -483,7 +481,7 @@ public void test_perform_simple_build_step_empty_hash() {
doReturn(new ArrayList<String>()).when(sn).lookupCommitSha1s(eq(build), eq(null), eq(buildListener));

//when
sn.perform(build, workspace, mock(Launcher.class), buildListener);
sn.perform(build, mock(Launcher.class), buildListener);

//then
verify(sn, never()).notifyStash(
Expand Down

0 comments on commit 89b23bc

Please sign in to comment.