0

Upload (per progress bottom bar status) goes through in Jenkins. But don't see option to locate or fetch uploaded file from Jenkins.

Here is simple script with File parameters,

properties(
    [
        parameters(
            [ file(name: "file1.zip", description: 'Choose path to upload file1.zip from local system.'),
              file(name: "file2.zip", description: 'Choose path to upload file2.zip from local system.') ]
            )
    ]
)

node {
    stage("Fetch Uploaded File") {
        sh '''
        ls -l file1.zip file2.zip
        ls -l ${WORKSPACE}/file1.zip ${WORKSPACE}/file2.zip
        '''
     }


}

Tried with def input file option per other post, but no luck of reaching uploaded file. Any inputs?

    def inputFile = input message: 'Upload file', parameters: [file(name: 'data.ear')]
    new hudson.FilePath(new File("$workspace/data.ear")).copyFrom(inputFile)
    inputFile.delete()

With scripted full pipeline pasted above, getting below error..

[Pipeline] {
[Pipeline] stage
[Pipeline] { (Fetch Uploaded File)
[Pipeline] sh
[testSh] Running shell script
+ ls -l file1.zip file2.zip
ls: cannot access file1.zip: No such file or directory
ls: cannot access file2.zip: No such file or directory
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 2
Finished: FAILURE
vinWin
  • 509
  • 1
  • 5
  • 18
  • Here is another failure attempt of trying it differently `node { stage("Upload File") { def inputFile = input message: 'Upload file', parameters: [file(name: 'data.zip')] new hudson.FilePath(new File("$WORKSPACE/data.zip")).copyFrom(inputFile) inputFile.delete() sh ''' ls -l data.zip ls -l ${WORKSPACE}/data.zip ''' } }` – vinWin Dec 24 '19 at 12:13
  • And corresponding error being.. `[Pipeline] { [Pipeline] stage [Pipeline] { (Upload File) [Pipeline] input Input requested Approved by admin [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new java.io.File java.lang.String at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectNew(StaticWhitelist.java:187) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance` – vinWin Dec 24 '19 at 12:14

1 Answers1

2

This is a known bug JENKINS-27413.

There is however a library with a workaround that can help you https://github.com/janvrany/jenkinsci-unstashParam-library. As described in the readme you can add this library to your Jenkins (Extending with Shared Libraries) and use it the following way:

library "jenkinsci-unstashParam-library"
node {
   def file_in_workspace = unstashParam "file"
   sh "cat ${file_in_workspace}"
}
Vitalii Vitrenko
  • 9,763
  • 4
  • 43
  • 62
  • Thanks for your response @Vitalii Vitrenko As it's binary, looked at slight variation as per here : https://stackoverflow.com/questions/57464227/upload-file-in-jenkins-input-step-to-workspace & is working now! – vinWin Dec 24 '19 at 14:59
  • 1
    Actually neither answer from https://stackoverflow.com/questions/57464227/upload-file-in-jenkins-input-step-to-workspace post is working not the solution which you pointed @Vitalii Vitrenko With other post it results in 'Can not open file '' as archive ' error and with solution which you pointed yields to following error : 'ERROR: unstashParam: No file parameter named 'file'' – vinWin Dec 24 '19 at 17:40
  • And to add, its binary file which I am looking to upload relatively huge, which is failing using either of approach – vinWin Dec 24 '19 at 17:47