2

In course of uploading binary file with few attempts per file parameter uploaded file in Jenkins is missing & Fetching binary or zipped uploaded files in Jenkins - Windows cannot open the folder . The Compressed(zipped) Folder is invalid noticed, writeFile Groovy used as part of Jnekins pipeline is corrupting content of file along with its size - worried more from Binary file perspective.

Per the documentation, https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#writefile-write-file-to-workspace , it's mentioned to support base64 encoding for binary data for writing files, but looks like it's bug as written file is with wrong size (exceeds..) & corrupt, as one can't open zip or binary file as highlighted in post linked above.

writeFile: Write file to workspace Write the given content to a named file in the current directory. file Type: String text Type: String encoding (optional) The target encoding for the file. If left blank, the platform default encoding will be used. If the text is a Base64-encoded string, the decoded binary data can be written to the file by specifying "Base64" as the encoding. Type: String

Any work-around is present or is there a way to raise bug-fix request?

Here is line of code which looks to be causing problem from groovy Jenkins pipeline script

 // Read contents and write to workspace
    writeFile(file: filename, encoding: 'Base64', text: filedata.read().getBytes().encodeBase64().toString())
vinWin
  • 509
  • 1
  • 5
  • 18
  • You appear to be doing the base64 encoding twice. – Matthew Schuchard Dec 27 '19 at 14:42
  • As per doc, it's specifying ;encoding; type as 'Base64' and actually doing as part of read with call to encodeBase64() . Am I missing something? – vinWin Dec 27 '19 at 14:45
  • instead of `writeFile` use something like: `new hudson.FilePath(new File("$workspace/$filename")).copyFrom(filedata)`. this should make a copy of uploaded file in the workspace... – daggett Dec 27 '19 at 15:57
  • Actually that excerpt of code is from this : https://issues.jenkins-ci.org/browse/JENKINS-27413?focusedCommentId=366085&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-366085 & as it is not within `stage` afraid we can use environment variable like $workspace – vinWin Dec 27 '19 at 16:44

0 Answers0