diff --git a/pom.xml b/pom.xml index 391b4fd..5f43e8b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,8 @@ org.jenkins-ci.plugins plugin - 3.2 + 3.43 + Groovy Postbuild @@ -11,7 +12,7 @@ groovy-postbuild 2.5-SNAPSHOT hpi - http://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin + https://wiki.jenkins.io/display/JENKINS/Groovy+Postbuild+Plugin @@ -27,17 +28,17 @@ The MIT license - http://www.opensource.org/licenses/mit-license.php + https://opensource.org/licenses/MIT repo - 2.60.3 + 2.121.1 8 1.2 - 2.14 - 2.45 + 2.20 + 2.69 @@ -50,7 +51,7 @@ repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ + https://repo.jenkins-ci.org/public/ @@ -87,7 +88,13 @@ org.jenkins-ci.plugins.workflow workflow-job - 2.10 + 2.32 + test + + + org.jenkins-ci.plugins.workflow + workflow-basic-steps + 2.15 test @@ -97,4 +104,38 @@ test + + + + org.jenkins-ci.plugins.workflow + workflow-step-api + ${workflow-step-api-plugin.version} + + + org.jenkins-ci.plugins.workflow + workflow-api + 2.33 + + + org.jenkins-ci.plugins.workflow + workflow-support + 3.3 + + + org.jenkins-ci.plugins + scm-api + 2.2.6 + + + org.jenkins-ci.plugins + structs + 1.19 + + + org.jenkins-ci.plugins + script-security + 1.60 + + + diff --git a/src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java b/src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java index effc804..78e37d3 100644 --- a/src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java +++ b/src/main/java/org/jvnet/hudson/plugins/groovypostbuild/GroovyPostbuildRecorder.java @@ -26,6 +26,7 @@ import groovy.lang.Binding; import hudson.AbortException; import hudson.EnvVars; +import hudson.Functions; import hudson.Launcher; import hudson.matrix.MatrixAggregatable; import hudson.matrix.MatrixAggregator; @@ -254,7 +255,7 @@ public void buildScriptFailed(Exception e) { @Whitelisted public boolean logContains(String regexp) { - return contains(build.getLogFile(), build.getCharset(), regexp); + return getLogMatcher(regexp) != null; } @@ -263,6 +264,7 @@ public boolean contains(File f, String regexp) { return contains(f, Charset.defaultCharset(), regexp); } + @Deprecated // not @Whitelisted unless we know what file that is public boolean contains(File f, Charset charset, String regexp) { Matcher matcher = getMatcher(f, charset, regexp); @@ -271,7 +273,13 @@ public boolean contains(File f, Charset charset, String regexp) { @Whitelisted public Matcher getLogMatcher(String regexp) { - return getMatcher(build.getLogFile(), build.getCharset(), regexp); + try (Reader r = build.getLogReader()) { + return getMatcher(r, regexp); + } catch (IOException e) { + Functions.printStackTrace(e, listener.error("Groovy Postbuild: logContains(\"" + regexp + "\") failed.")); + buildScriptFailed(e); + return null; + } } @Deprecated @@ -279,10 +287,9 @@ public Matcher getMatcher(File f, String regexp) { return getMatcher(f, Charset.defaultCharset(), regexp); } - public Matcher getMatcher(File f, Charset charset, String regexp) { - LOGGER.fine("Searching for '" + regexp + "' in '" + f + "'."); + public Matcher getMatcher(Reader r, String regexp) { Matcher matcher = null; - try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), charset))) { + try (BufferedReader reader = new BufferedReader(r)) { Pattern pattern = compilePattern(regexp); // Assume default encoding and text files String line; @@ -294,10 +301,23 @@ public Matcher getMatcher(File f, Charset charset, String regexp) { } } } catch (IOException e) { - e.printStackTrace(listener.error("Groovy Postbuild: getMatcher(\"" + f + "\", \"" + regexp + "\") failed.")); + Functions.printStackTrace(e, listener.error("Groovy Postbuild: getMatcher(…, \"" + regexp + "\") failed.")); buildScriptFailed(e); } return matcher; + + } + + @Deprecated + public Matcher getMatcher(File f, Charset charset, String regexp) { + LOGGER.fine("Searching for '" + regexp + "' in '" + f + "'."); + try (InputStream is = new FileInputStream(f); Reader r = new InputStreamReader(is, charset)) { + return getMatcher(r, regexp); + } catch (IOException e) { + Functions.printStackTrace(e, listener.error("Groovy Postbuild: getMatcher(\"" + f + "\", \"" + regexp + "\") failed.")); + buildScriptFailed(e); + } + return null; } private Pattern compilePattern(String regexp) throws AbortException { diff --git a/src/test/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowTest.java b/src/test/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowTest.java index 1bf4af9..ad9fa3e 100644 --- a/src/test/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowTest.java +++ b/src/test/java/org/jvnet/hudson/plugins/groovypostbuild/WorkflowTest.java @@ -33,12 +33,18 @@ import org.jvnet.hudson.test.JenkinsRule; import com.jenkinsci.plugins.badge.action.BadgeAction; +import java.util.Collections; +import java.util.logging.Level; +import org.jvnet.hudson.test.LoggerRule; public class WorkflowTest { @Rule public JenkinsRule r = new JenkinsRule(); + @Rule + public LoggerRule logging = new LoggerRule(); + @Issue("JENKINS-26918") @Test public void usingManager() throws Exception { @@ -48,4 +54,18 @@ public void usingManager() throws Exception { assertEquals("stuff is broken", b.getAction(BadgeAction.class).getText()); } + @Issue("JENKINS-54128") + @Test + public void logContains() throws Exception { + WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); + p.setDefinition(new CpsFlowDefinition( + "echo '1st message'\n" + + "echo '2nd message'\n" + + "sleep 1\n" + // to flush output (inspecting Run.log from the build itself is unreliable; use a TaskListenerDecorator instead) + "echo(/found first message? ${manager.logContains(/1st message/)} second? ${manager.logContains(/2nd message/)} third? ${manager.logContains(/3rd message/)} /); ", true)); + logging.record(WorkflowRun.class, Level.WARNING).capture(100); + r.assertLogContains("found first message? true second? true third? false", r.assertBuildStatusSuccess(p.scheduleBuild2(0))); + assertEquals(Collections.emptyList(), logging.getRecords()); + } + }