From a95a587d38256ba2e615e5042b3b5af544326c81 Mon Sep 17 00:00:00 2001 From: "Hirschauer, Nathan-Jedidja" Date: Mon, 9 Dec 2024 13:10:37 +0100 Subject: [PATCH] #234: Do not require a workspace to notify Bitbucket 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. --- .../plugins/stashNotifier/StashNotifier.java | 19 ++++++++++++------- .../stashNotifier/StashNotifierTest.java | 6 ++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/stashNotifier/StashNotifier.java b/src/main/java/org/jenkinsci/plugins/stashNotifier/StashNotifier.java index d91c3a9..08b7f1f 100644 --- a/src/main/java/org/jenkinsci/plugins/stashNotifier/StashNotifier.java +++ b/src/main/java/org/jenkinsci/plugins/stashNotifier/StashNotifier.java @@ -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.*; @@ -361,26 +362,30 @@ 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 TaskListener listener) { - if (!perform(run, workspace, listener, false)) { + public void perform( + @NonNull Run run, + @NonNull EnvVars env, + @NonNull TaskListener listener) { + if (!perform(run, listener, false)) { run.setResult(Result.FAILURE); } } private boolean perform(Run run, - FilePath workspace, TaskListener listener, boolean disableInProgress) { StashBuildState state; diff --git a/src/test/java/org/jenkinsci/plugins/stashNotifier/StashNotifierTest.java b/src/test/java/org/jenkinsci/plugins/stashNotifier/StashNotifierTest.java index 304bed9..4e0e5e4 100644 --- a/src/test/java/org/jenkinsci/plugins/stashNotifier/StashNotifierTest.java +++ b/src/test/java/org/jenkinsci/plugins/stashNotifier/StashNotifierTest.java @@ -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 { @@ -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); @@ -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)); @@ -483,7 +481,7 @@ public void test_perform_simple_build_step_empty_hash() { doReturn(new ArrayList()).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(