Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bcfe6a5
First draft of integration with new watch/Handler API.
jglick Oct 4, 2016
c080e32
Integration test for remote logging.
jglick Oct 5, 2016
4ad8e75
Reminder to pick up https://github.com/jenkinsci/jenkins-test-harness…
jglick Oct 6, 2016
1991f14
[FIXED JENKINS-31096] Proving that recoding in FileMonitoringTask.Wat…
jglick Oct 6, 2016
8c2f510
Picking up 1.17 test harness.
jglick Oct 10, 2016
2c43dba
BindingStepTest equivalent demonstrating that a ConsoleLogFilter may …
jglick Oct 10, 2016
940d360
jitpack.io for upstream https://github.com/jenkinsci/maven-hpi-plugin…
jglick Dec 7, 2016
6197075
Simpler idiom for tracking the name of an agent.
jglick Dec 8, 2016
de034fa
hpi-plugin.version=1.121
jglick Dec 16, 2016
a8dafb0
Extended JENKINS-34021 coverage to watch mode.
jglick Dec 20, 2016
363bafa
getLog should take a long start argument.
jglick Dec 21, 2016
0e00b9d
Merge branch 'robustness-JENKINS-40613' into logs-JENKINS-38381
jglick Jan 3, 2017
178c4e3
Giving up on jitpack for now.
jglick Jan 3, 2017
5dbf17e
Merge branch 'master' into logs-JENKINS-38381
jglick Jan 6, 2017
e8f5ab9
New snapshots.
jglick Jan 9, 2017
6f2f928
Merge branch 'master' into logs-JENKINS-38381
jglick Feb 5, 2018
1b89cb7
Minor additional fixups.
jglick Feb 5, 2018
b983dca
Fixing minor build issues.
jglick Feb 5, 2018
4e53e76
Test from https://github.com/jenkinsci/workflow-durable-task-step-plu…
jglick Feb 5, 2018
9e36ef2
Merge branch 'watch-JENKINS-38381' into logs-JENKINS-38381
jglick Feb 9, 2018
99301e5
Merge branch 'watch-plus-UTF-8-JENKINS-31096' into logs-JENKINS-38381
jglick Feb 13, 2018
c886dbc
Merge branch 'watch-plus-UTF-8-JENKINS-31096' into logs-JENKINS-38381
jglick Jun 11, 2018
cf9703d
requireUpperBoundDeps
jglick Jun 11, 2018
34125ba
Deleting LessAbstractTaskListener as it is superseded by https://gith…
jglick Jun 11, 2018
8601150
Superfluous double build.
jglick Jun 11, 2018
74dc7c3
Suppressing a new test on Windows for the moment.
jglick Jun 11, 2018
a9ef0c6
Some updates.
jglick Jun 18, 2018
4cf6db4
Refactored to LogStorage.
jglick Jun 20, 2018
46b4f43
Bumps.
jglick Jun 21, 2018
9040974
Merge branch 'watch-JENKINS-38381' into logs-JENKINS-38381
jglick Aug 7, 2018
9594a9e
Merge branch 'watch-JENKINS-38381' into logs-JENKINS-38381
jglick Aug 8, 2018
04562f4
Adapted to https://github.com/jenkinsci/workflow-api-plugin/pull/17/c…
jglick Aug 10, 2018
7b07da9
Merge branch 'watch-JENKINS-38381' into logs-JENKINS-38381
jglick Aug 13, 2018
1a53d3d
Now using FileLogStorage.
jglick Aug 13, 2018
8668f02
Merge branch 'watch-JENKINS-38381' into logs-JENKINS-38381
jglick Aug 14, 2018
dfadac1
More interesting ShellStepTest.remoteLogger: upcase output on the rem…
jglick Aug 15, 2018
a8e9da4
Merge branch 'watch-JENKINS-38381' into logs-JENKINS-38381
jglick Aug 22, 2018
77b8bd3
Merge branch 'watch-JENKINS-38381' into logs-JENKINS-38381
jglick Sep 4, 2018
c66d650
Merge branch 'watch-JENKINS-38381' into logs-JENKINS-38381
jglick Sep 4, 2018
587b863
Bumps.
jglick Sep 4, 2018
221f1ac
Added another test demonstrating that watch mode with an external log…
jglick Sep 4, 2018
9674f84
Speeding up priming builds for ShellStepTest.remoteVoluminousLogger.
jglick Sep 5, 2018
2558f96
Merge branch 'master' into logs-JENKINS-38381
jglick Sep 13, 2018
b97162b
Merge branch 'master' into logs-JENKINS-38381
jglick Sep 25, 2018
648d2f2
Bumps.
jglick Sep 25, 2018
68614d2
Flaky test.
jglick Sep 25, 2018
d8d15fc
Using release versions.
jglick Oct 4, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<jenkins.version>2.73.3</jenkins.version>
<java.level>8</java.level>
<workflow-step-api-plugin.version>2.13</workflow-step-api-plugin.version>
<workflow-support-plugin.version>2.19-20180209.204154-1</workflow-support-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-support-plugin/pull/56 -->
<workflow-support-plugin.version>2.19-20180213.183111-2</workflow-support-plugin.version> <!-- TODO https://github.com/jenkinsci/workflow-support-plugin/pull/15 -->
</properties>
<dependencies>
<dependency>
Expand All @@ -81,7 +81,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.25</version>
<version>2.26-SNAPSHOT</version> <!-- TODO pending https://github.com/jenkinsci/workflow-api-plugin/pull/17 -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand All @@ -97,13 +97,13 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.18-20180209.215341-1</version> <!-- TODO https://github.com/jenkinsci/workflow-job-plugin/pull/89 -->
<version>2.18-20180213.183217-2</version> <!-- TODO pending https://github.com/jenkinsci/workflow-job-plugin/pull/27 -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>1.15</version>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -126,6 +126,12 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
<version>1.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-scm-step</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
package org.jenkinsci.plugins.workflow.steps.durable_task;

import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import com.google.common.base.Predicate;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.EnvVars;
import hudson.Functions;
import hudson.Launcher;
import hudson.LauncherDecorator;
import hudson.console.LineTransformationOutputStream;
import hudson.model.BallColor;
import hudson.model.BuildListener;
import hudson.model.FreeStyleProject;
import hudson.model.Node;
import hudson.model.Result;
import hudson.remoting.Channel;
import hudson.model.Slave;
import hudson.slaves.DumbSlave;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.tasks.BatchFile;
import hudson.tasks.Shell;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Serializable;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.StandardOpenOption;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
Expand All @@ -27,12 +45,14 @@
import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.job.console.PipelineLogFile;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
import org.jenkinsci.plugins.workflow.steps.BodyInvoker;
import org.jenkinsci.plugins.workflow.steps.StepConfigTester;
import org.jenkinsci.plugins.workflow.support.actions.LessAbstractTaskListener;
import org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable;
import org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable.Row;
import static org.junit.Assert.*;
Expand Down Expand Up @@ -237,6 +257,87 @@ public DescriptorImpl() {
j.assertLogContains("truth is 0 but falsity is 1", j.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}

@Issue("JENKINS-38381")
@Test public void remoteLogger() throws Exception {
final String credentialsId = "creds";
final String username = "bob";
final String password = "s3cr3t";
UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample", username, password);
CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), c);
j.createSlave("remote", null, null);
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node('master') {\n" +
" sh 'pwd'\n" +
"}\n" +
"node('remote') {\n" +
" sh 'pwd'\n" +
" sh 'echo on agent'\n" +
" withCredentials([[$class: 'UsernamePasswordBinding', variable: 'USERPASS', credentialsId: '" + credentialsId + "']]) {\n" +
" sh 'set +x; echo curl -u $USERPASS http://server/'\n" +
" }\n" +
"}", true));
WorkflowRun b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
j.assertLogContains("+ pwd [master #1]", b);
j.assertLogContains("+ pwd [master #1 → remote #", b);
j.assertLogContains("on agent [master #1 → remote #", b);
j.assertLogNotContains(password, b);
j.assertLogContains("curl -u **** http://server/ [master #1 → remote #", b);
}
@TestExtension("remoteLogger") public static class LogFile extends PipelineLogFile {
@Override protected BuildListener listenerFor(WorkflowRun b) throws IOException, InterruptedException {
return new RemotableBuildListener(logFile(b));
}
@Override protected InputStream logFor(WorkflowRun b, long start) throws IOException {
return Channels.newInputStream(FileChannel.open(logFile(b).toPath(), StandardOpenOption.READ).position(start));
}
File logFile(WorkflowRun b) {
return new File(b.getRootDir(), "special.log");
}
}
private static class RemotableBuildListener extends LessAbstractTaskListener implements BuildListener {
private static final long serialVersionUID = 1;
/** counts which instance this is per JVM */
private static final AtomicInteger instantiationCounter = new AtomicInteger();
/** location of log file streamed to by multiple sources */
private final File logFile;
/** records allocation & deserialization history; e.g., {@code master #1 → agent #1} */
private final String id;
private transient PrintStream logger;
RemotableBuildListener(File logFile) {
this(logFile, "master #" + instantiationCounter.incrementAndGet());
}
private RemotableBuildListener(File logFile, String id) {
this.logFile = logFile;
this.id = id;
}
@Override public PrintStream getLogger() {
if (logger == null) {
final OutputStream fos;
try {
fos = new FileOutputStream(logFile, true);
} catch (FileNotFoundException x) {
throw new AssertionError(x);
}
logger = new PrintStream(new LineTransformationOutputStream() {
@Override protected void eol(byte[] b, int len) throws IOException {
fos.write(b, 0, len - 1); // all but NL
fos.write((" [" + id + "]").getBytes(StandardCharsets.UTF_8));
fos.write(b[len - 1]); // NL
}
});
}
return logger;
}
private Object writeReplace() {
/* To see serialization happening from BourneShellScript.launchWithCookie & FileMonitoringController.watch:
Thread.dumpStack();
*/
String name = Channel.current().getName();
return new RemotableBuildListener(logFile, id + " → " + name + " #" + instantiationCounter.incrementAndGet());
}
}

@Issue("JENKINS-31096")
@Test public void encoding() throws Exception {
// Like JenkinsRule.createSlave but passing a system encoding:
Expand Down