jenkinsci / jenkinsci/workflow-basic-steps-plugin
[JENKINS-53151] withContext not working as expected in combination with consoleLogFilter
- Lingua principale
- Java
- Stelle
- 73
- Fork
- 129
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
I'm trying to make a custom ConsoleLogFilter in my pipeline script, however for some reason it breaks the echo functionality.
Here's my code:
final class TestStream extends OutputStream {
private final OutputStream delegate;
TestStream(OutputStream delegate) {
this.delegate = delegate
}
public void write(int b) throws IOException {
delegate.write(b);
}
public void write(byte[] b) throws IOException {
delegate.write(b);
}
public void write(byte[] b, int off, int len) throws IOException {
delegate.write(b, off, len);
}
public void flush() throws IOException {
delegate.flush();
}
public void close() throws IOException {
delegate.close();
}
}
class TestFilter extends ConsoleLogFilter {
@Override
public OutputStream decorateLogger(AbstractBuild build, OutputStream logger)
throws IOException, InterruptedException {
if (logger == null) {
return null;
}
return new TestStream(logger)
}
}
ConsoleLogFilter subsequent = new TestFilter();
ConsoleLogFilter original = getContext(ConsoleLogFilter.class);
println original //prints null
timestamps {
original = getContext(ConsoleLogFilter.class);
println original //prints TimestampNotesConsoleLogFilter object
echo "Out of Context" //Visible
withContext(BodyInvoker.mergeConsoleLogFilters(original, subsequent)) {
echo "In context " //Not visible
}
withContext(new TestFilter()) {
echo "In context " //Not visible
}
}
Here is the output:
Started by user jenkins
Running in Durability level: PERFORMANCE_OPTIMIZED
[Pipeline] getContext
[Pipeline] echo
null
[Pipeline] timestamps
[Pipeline] {
[Pipeline] getContext
[Pipeline] echo
07:22:58 hudson.plugins.timestamper.pipeline.TimestamperStep$TimestampNotesConsoleLogFilter@1d678d7a
[Pipeline] echo
07:22:58 Out of Context
[Pipeline] withContext
[Pipeline] {
[Pipeline] echo
[Pipeline] }
[Pipeline] // withContext
[Pipeline] withContext
[Pipeline] {
[Pipeline] echo
[Pipeline] }
[Pipeline] // withContext
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] End of Pipeline
Finished: SUCCESS
The 'in context' print is never written to the outputstream
---
Originally reported by roel0, imported from: withContext not working as expected in combination with consoleLogFilter
Raw content of original issue
I'm trying to make a custom ConsoleLogFilter in my pipeline script, however for some reason it breaks the echo functionality.
Here's my code:
final class TestStream extends OutputStream {
private final OutputStream delegate;
TestStream(OutputStream delegate) {
this.delegate = delegate
}
public void write(int b) throws IOException {
delegate.write(b);
}
public void write(byte[] b) throws IOException {
delegate.write(b);
}
public void write(byte[] b, int off, int len) throws IOException {
delegate.write(b, off, len);
}
public void flush() throws IOException {
delegate.flush();
}
public void close() throws IOException {
delegate.close();
}
}
class TestFilter extends ConsoleLogFilter {
@Override
public OutputStream decorateLogger(AbstractBuild build, OutputStream logger)
throws IOException, InterruptedException {
if (logger == null) {
return null;
}
return new TestStream(logger)
}
}
ConsoleLogFilter subsequent = new TestFilter();
ConsoleLogFilter original = getContext(ConsoleLogFilter.class);
println original //prints null
timestamps {
original = getContext(ConsoleLogFilter.class);
println original //prints TimestampNotesConsoleLogFilter object
echo "Out of Context" //Visible
withContext(BodyInvoker.mergeConsoleLogFilters(original, subsequent)) {
echo "In context " //Not visible
}
withContext(new TestFilter()) {
echo "In context " //Not visible
}
}Here is the output:
Started by user jenkins
Running in Durability level: PERFORMANCE_OPTIMIZED
[Pipeline] getContext
[Pipeline] echo
null
[Pipeline] timestamps
[Pipeline] {
[Pipeline] getContext
[Pipeline] echo
07:22:58 hudson.plugins.timestamper.pipeline.TimestamperStep$TimestampNotesConsoleLogFilter@1d678d7a
[Pipeline] echo
07:22:58 Out of Context
[Pipeline] withContext
[Pipeline] {
[Pipeline] echo
[Pipeline] }
[Pipeline] // withContext
[Pipeline] withContext
[Pipeline] {
[Pipeline] echo
[Pipeline] }
[Pipeline] // withContext
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] End of Pipeline
Finished: SUCCESS
The 'in context' print is never written to the outputstream
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Leggi i punti di ingresso della voce workflow-basic-steps-plugin per withContext ed echo, quindi segui BodyInvoker.mergeConsoleLogFilters e ConsoleLogFilter usando la riproduzione della pipeline fornita. Il lavoro è completato quando le righe di echo “In context” vengono scritte nel flusso di output quando viene applicato un filtro personalizzato, mentre il comportamento esistente dei timestamp rimane visibile.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 39/100