Skip to content

Commit

Permalink
Merge pull request #199 from lne3/JENKINS-72436
Browse files Browse the repository at this point in the history
[JENKINS-72436] `sh` step on z/OS with `encoding` set to UTF-8 hangs when trying to read `jenkins-result.txt`
  • Loading branch information
jglick authored Jan 5, 2024
2 parents 8c179f9 + 0d243db commit 262f6a8
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,18 @@ public String getScript() {

OsType os = agentInfo.getOs();
String scriptEncodingCharset = "UTF-8";
String jenkinsResultTxtEncoding = null;
if(os == OsType.ZOS) {
Charset zOSSystemEncodingCharset = Charset.forName(ws.act(new getIBMzOsEncoding()));
if(SYSTEM_DEFAULT_CHARSET.equals(getCharset())) {
// Setting default charset to IBM z/OS default EBCDIC charset on z/OS if no encoding specified on sh step
charset(zOSSystemEncodingCharset);
}
scriptEncodingCharset = zOSSystemEncodingCharset.name();
jenkinsResultTxtEncoding = zOSSystemEncodingCharset.name();

Check warning on line 138 in src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 138 is not covered by tests
}

ShellController c = new ShellController(ws,(os == OsType.ZOS), cookieValue);
ShellController c = new ShellController(ws,(os == OsType.ZOS), cookieValue, jenkinsResultTxtEncoding);

Check warning on line 141 in src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 141 is only partially covered, one branch is missing
FilePath shf = c.getScriptFile(ws);

shf.write(script, scriptEncodingCharset);
Expand Down Expand Up @@ -275,10 +277,13 @@ private List<String> scriptLauncherCmd(ShellController c, FilePath ws, @CheckFor

/** Caching zOS flag to avoid round trip calls in exitStatus() */
private final boolean isZos;
/** Encoding of jenkins-result.txt if on z/OS, null otherwise */
private String jenkinsResultTxtEncoding;

private ShellController(FilePath ws, boolean zOsFlag, @NonNull String cookieValue) throws IOException, InterruptedException {
private ShellController(FilePath ws, boolean zOsFlag, @NonNull String cookieValue, String jenkinsResultTxtEncoding) throws IOException, InterruptedException {
super(ws, cookieValue);
this.isZos = zOsFlag;
this.jenkinsResultTxtEncoding = jenkinsResultTxtEncoding;
}

public FilePath getScriptFile(FilePath ws) throws IOException, InterruptedException {
Expand All @@ -295,7 +300,7 @@ private FilePath pidFile(FilePath ws) throws IOException, InterruptedException {
if(isZos) {
// We need to transcode status file from EBCDIC only on z/OS platform
FilePath statusFile = getResultFile(workspace);
status = statusFile.act(new StatusCheckWithEncoding(getCharset()));
status = statusFile.act(new StatusCheckWithEncoding(jenkinsResultTxtEncoding != null ? jenkinsResultTxtEncoding : getCharset()));
}
else {
status = super.exitStatus(workspace, listener);
Expand Down Expand Up @@ -385,7 +390,7 @@ public Integer invoke(File f, VirtualChannel channel) throws IOException, Interr
}
}
} catch (NumberFormatException x) {
throw new IOException("corrupted content in " + f + ": " + x, x);
throw new IOException("corrupted content in " + f + " using " + charset + ": " + x, x);

Check warning on line 393 in src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 303-393 are not covered by tests
}
}
return null;
Expand Down

0 comments on commit 262f6a8

Please sign in to comment.