-
-
Notifications
You must be signed in to change notification settings - Fork 105
[JEP-206] Gather command output in a local encoding #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
dec68db
6f2bf2e
23a1dde
1f4493f
0dcf951
35b0234
36722de
75181a5
54b2187
8c763a4
d3508c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ | |
| <parent> | ||
| <groupId>org.jenkins-ci.plugins</groupId> | ||
| <artifactId>plugin</artifactId> | ||
| <version>3.2</version> | ||
| <version>3.4</version> | ||
| <relativePath /> | ||
| </parent> | ||
| <groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
|
|
@@ -62,9 +62,10 @@ | |
| </pluginRepository> | ||
| </pluginRepositories> | ||
| <properties> | ||
| <jenkins.version>2.60.3</jenkins.version> | ||
| <jenkins.version>2.73.3</jenkins.version> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this gratuitous or do we need a new API?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test dep on |
||
| <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 --> | ||
| </properties> | ||
| <dependencies> | ||
| <dependency> | ||
|
|
@@ -75,17 +76,17 @@ | |
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins</groupId> | ||
| <artifactId>durable-task</artifactId> | ||
| <version>1.18-20180125.194359-1</version> <!-- TODO https://github.com/jenkinsci/durable-task-plugin/pull/57 --> | ||
| <version>1.18-20180212.221815-3</version> <!-- TODO https://github.com/jenkinsci/durable-task-plugin/pull/61 --> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
| <artifactId>workflow-api</artifactId> | ||
| <version>2.22</version> | ||
| <version>2.25</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
| <artifactId>workflow-support</artifactId> | ||
| <version>2.16</version> | ||
| <version>${workflow-support-plugin.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
|
|
@@ -96,7 +97,7 @@ | |
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
| <artifactId>workflow-job</artifactId> | ||
| <version>2.9</version> | ||
| <version>2.18-20180209.215341-1</version> <!-- TODO https://github.com/jenkinsci/workflow-job-plugin/pull/89 --> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
|
|
@@ -121,7 +122,7 @@ | |
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
| <artifactId>workflow-support</artifactId> | ||
| <version>2.13</version> | ||
| <version>${workflow-support-plugin.version}</version> | ||
| <classifier>tests</classifier> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
@@ -134,12 +135,17 @@ | |
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins</groupId> | ||
| <artifactId>script-security</artifactId> | ||
| <version>1.27</version> | ||
| <version>1.39</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins</groupId> | ||
| <artifactId>structs</artifactId> | ||
| <version>1.7</version> | ||
| <version>1.10</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.jenkins-ci.plugins</groupId> | ||
| <artifactId>scm-api</artifactId> | ||
| <version>2.2.6</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,13 +30,15 @@ | |
| import hudson.EnvVars; | ||
| import hudson.FilePath; | ||
| import hudson.Launcher; | ||
| import hudson.Util; | ||
| import hudson.model.TaskListener; | ||
| import hudson.util.DaemonThreadFactory; | ||
| import hudson.util.FormValidation; | ||
| import hudson.util.LogTaskListener; | ||
| import hudson.util.NamingThreadFactory; | ||
| import java.io.IOException; | ||
| import java.nio.charset.Charset; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ScheduledFuture; | ||
| import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
|
|
@@ -67,7 +69,7 @@ public abstract class DurableTaskStep extends Step { | |
| private static final Logger LOGGER = Logger.getLogger(DurableTaskStep.class.getName()); | ||
|
|
||
| private boolean returnStdout; | ||
| private String encoding = DurableTaskStepDescriptor.defaultEncoding; | ||
| private String encoding; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this is a behavioral change—we are changing the default value of I tried to think of a way to keep the previous default but it was just going to be ugly. With the change of the overall build log to UTF-8, it would mean that you would get mojibake in case you were running, say, entirely on CP-1252 Windows (with or without agents) and just did something simple like node {
bat 'something producing Western European characters…'
}which seems wrong. This interpretation of Obviously if you have specific knowledge that a given process is going to be producing UTF-8 yet will be running on a node with a different system encoding (typically Windows, since every Linux distribution has defaulted to UTF-8 for a long time), you can make that explicit with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🐛 This should be called out really explicitly in the documentation / UI here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I can emphasize that.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems reasonable. Whatever is done with encodings in Durable Task and this plugin, it is a risky change anyway. Since the idea is to NOT enforce the UTF encoding, the current approach looks preferable |
||
| private boolean returnStatus; | ||
|
|
||
| protected abstract DurableTask task(); | ||
|
|
@@ -85,7 +87,7 @@ public String getEncoding() { | |
| } | ||
|
|
||
| @DataBoundSetter public void setEncoding(String encoding) { | ||
| this.encoding = encoding; | ||
| this.encoding = Util.fixEmpty(encoding); | ||
| } | ||
|
|
||
| public boolean isReturnStatus() { | ||
|
|
@@ -102,17 +104,15 @@ public boolean isReturnStatus() { | |
|
|
||
| public abstract static class DurableTaskStepDescriptor extends StepDescriptor { | ||
|
|
||
| public static final String defaultEncoding = "UTF-8"; | ||
|
|
||
| public FormValidation doCheckEncoding(@QueryParameter boolean returnStdout, @QueryParameter String encoding) { | ||
| if (encoding.isEmpty()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a web method; the text field may be blank but not missing. |
||
| return FormValidation.ok(); | ||
| } | ||
| try { | ||
| Charset.forName(encoding); | ||
| } catch (Exception x) { | ||
| return FormValidation.error(x, "Unrecognized encoding"); | ||
| } | ||
| if (!returnStdout && !encoding.equals(DurableTaskStepDescriptor.defaultEncoding)) { | ||
| return FormValidation.warning("encoding is ignored unless returnStdout is checked."); | ||
| } | ||
| return FormValidation.ok(); | ||
| } | ||
|
|
||
|
|
@@ -154,7 +154,6 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab | |
| private String node; | ||
| private String remote; | ||
| private boolean returnStdout; // serialized default is false | ||
| private String encoding; // serialized default is irrelevant | ||
| private boolean returnStatus; // serialized default is false | ||
|
|
||
| Execution(StepContext context, DurableTaskStep step) { | ||
|
|
@@ -164,7 +163,6 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab | |
|
|
||
| @Override public boolean start() throws Exception { | ||
| returnStdout = step.returnStdout; | ||
| encoding = step.encoding; | ||
| returnStatus = step.returnStatus; | ||
| StepContext context = getContext(); | ||
| ws = context.get(FilePath.class); | ||
|
|
@@ -173,6 +171,11 @@ static final class Execution extends AbstractStepExecutionImpl implements Runnab | |
| if (returnStdout) { | ||
| durableTask.captureOutput(); | ||
| } | ||
| if (step.encoding != null) { | ||
| durableTask.charset(Charset.forName(step.encoding)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catch/rethrow exception with more debug details?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which debug details are you looking for here? |
||
| } else { | ||
| durableTask.defaultCharset(); | ||
| } | ||
| controller = durableTask.launch(context.get(EnvVars.class), ws, context.get(Launcher.class), context.get(TaskListener.class)); | ||
| this.remote = ws.getRemote(); | ||
| setupTimer(); | ||
|
|
@@ -327,7 +330,7 @@ private void check() { | |
| LOGGER.log(Level.FINE, "last-minute output in {0} on {1}", new Object[] {remote, node}); | ||
| } | ||
| if (returnStatus || exitCode == 0) { | ||
| getContext().onSuccess(returnStatus ? exitCode : returnStdout ? new String(controller.getOutput(workspace, launcher()), encoding) : null); | ||
| getContext().onSuccess(returnStatus ? exitCode : returnStdout ? new String(controller.getOutput(workspace, launcher()), StandardCharsets.UTF_8) : null); | ||
| } else { | ||
| if (returnStdout) { | ||
| listener.getLogger().write(controller.getOutput(workspace, launcher())); // diagnostic | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| <div> | ||
| Encoding of standard output, if it is being captured. | ||
| Encoding of process output. | ||
| In the case of <code>returnStdout</code>, applies to the return value of this step; | ||
| otherwise, or always for standard error, controls how text is copied to the build log. | ||
| If unspecified, uses the system default encoding of the node on which the step is run. | ||
| </div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.6 if 2.107.1 is added to CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now 3.7.