2
votes

I am creating a Jenkins pipeline job that asks for a file from user to upload. Here is the snippet:

stage('Upload a file') {
        def inFile = input id: 'file1', message: 'Upload a file', parameters: [file(name: 'data.tmp', description: 'Choose a file')]
        sh "echo \\\"Uploaded ${inFile}\\\"" 
}

When I uploaded a zip file "data123.zip", this original filename is lost and is renamed to "data.tmp", which is what I obtain from the variable inFile.

Other things that I tried that didn't work (I know some of them are silly):

  1. ${inFile.remote}
  2. file(name: '')
  3. file(description: '')
  4. ${file1}

Do you know if it's possible to get the original filename when uploading a file using Jenkins pipeline input step?

1

1 Answers

1
votes

As far as I can tell, you can't do this right now.

See this code in Jenkins - the original file name is simply not available in the FilePath object that gets returned by the input step: https://github.com/jenkinsci/pipeline-input-step-plugin/blob/41d514d266722433181e860d8cf90d56bca5046e/src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/InputStepExecution.java#L385