1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-09-16 09:26:22 +02:00

jenkinsMaterialzeLog: use log without binary annotations (#1542)

* jenkinsMaterialzeLog: use log without binary annotations

* test fixed
This commit is contained in:
lndrschlz
2020-05-18 21:19:30 +02:00
committed by GitHub
parent 4a82eb5aaa
commit b9a357bab5
2 changed files with 11 additions and 4 deletions

View File

@@ -1,4 +1,9 @@
import hudson.FilePath
import hudson.console.AnnotatedLargeText
import java.io.Writer
import groovy.mock.interceptor.MockFor
import java.lang.Integer
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
@@ -27,6 +32,10 @@ class JenkinsMaterializeLogTest extends BasePiperTest {
}
}
class AnnotatedLargeTextMock {
void writeLogTo(i, out) {}
}
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
@@ -40,7 +49,7 @@ class JenkinsMaterializeLogTest extends BasePiperTest {
void testMaterializeLog() {
def map = [script: nullScript, jenkinsUtilsStub: new JenkinsUtilsMock()]
def body = { name -> def msg = "hello " + name }
binding.setVariable('currentBuild', [result: 'UNSTABLE', rawBuild: [getLogInputStream: {return new StringBufferInputStream("this is the input")}]])
binding.setVariable('currentBuild', [result: 'UNSTABLE', rawBuild: [getLogText: { return new AnnotatedLargeTextMock() } ]])
binding.setVariable('env', [NODE_NAME: 'anynode', WORKSPACE: '.'])
stepRule.step.jenkinsMaterializeLog(map, body)
}

View File

@@ -37,9 +37,7 @@ void call(Map parameters = [:], body) {
@NonCPS
def writeLogToFile(fp) {
def logInputStream = currentBuild.rawBuild.getLogInputStream()
fp.copyFrom(logInputStream)
logInputStream.close()
currentBuild.rawBuild.getLogText().writeLogTo(0, fp.write())
}
@NonCPS