Skip to content

Commit

Permalink
Merge pull request #204 from ckullabosch/master
Browse files Browse the repository at this point in the history
[JENKINS-70874] Fix 'Text file busy' issue
  • Loading branch information
jglick authored Feb 6, 2024
2 parents d1ea007 + b70d63e commit 0930093
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public String getScript() {
ShellController c = new ShellController(ws,(os == OsType.ZOS), cookieValue, jenkinsResultTxtEncoding);
FilePath shf = c.getScriptFile(ws);

// JENKINS-70874: if a new process is forked during this call, the writeable file handle will be copied and leading to the "Text file busy" issue
// when executing the script.
shf.write(script, scriptEncodingCharset);

String shell = null;
Expand Down Expand Up @@ -229,27 +231,32 @@ private List<String> scriptLauncherCmd(ShellController c, FilePath ws, @CheckFor
if (os == OsType.WINDOWS) { // JENKINS-40255
scriptPath = scriptPath.replace("\\", "/"); // cygwin sh understands mixed path (ie : "c:/jenkins/workspace/script.sh" )
}
String scriptPathCopy = scriptPath + ".copy"; // copy file to protect against "Text file busy", see JENKINS-70874
if (capturingOutput) {
cmdString = String.format("{ while [ -d '%s' -a \\! -f '%s' ]; do touch '%s'; sleep 3; done } & jsc=%s; %s=$jsc %s '%s' > '%s' 2> '%s'; echo $? > '%s.tmp'; mv '%s.tmp' '%s'; wait",
cmdString = String.format("cp '%s' '%s'; { while [ -d '%s' -a \\! -f '%s' ]; do touch '%s'; sleep 3; done } & jsc=%s; %s=$jsc %s '%s' > '%s' 2> '%s'; echo $? > '%s.tmp'; mv '%s.tmp' '%s'; wait",
scriptPath,
scriptPathCopy,
controlDir,
resultFile,
logFile,
cookieValue,
cookieVariable,
interpreter,
scriptPath,
scriptPathCopy,
c.getOutputFile(ws),
logFile,
resultFile, resultFile, resultFile);
} else {
cmdString = String.format("{ while [ -d '%s' -a \\! -f '%s' ]; do touch '%s'; sleep 3; done } & jsc=%s; %s=$jsc %s '%s' > '%s' 2>&1; echo $? > '%s.tmp'; mv '%s.tmp' '%s'; wait",
cmdString = String.format("cp '%s' '%s'; { while [ -d '%s' -a \\! -f '%s' ]; do touch '%s'; sleep 3; done } & jsc=%s; %s=$jsc %s '%s' > '%s' 2>&1; echo $? > '%s.tmp'; mv '%s.tmp' '%s'; wait",
scriptPath,
scriptPathCopy,
controlDir,
resultFile,
logFile,
cookieValue,
cookieVariable,
interpreter,
scriptPath,
scriptPathCopy,
logFile,
resultFile, resultFile, resultFile);
}
Expand Down

0 comments on commit 0930093

Please sign in to comment.