Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Pipeline Job with file parameter

I'm putting together a Jenkins pipeline job which will take a file parameter. I can trigger the job and point it at a file however I can't find where the file has ended up (In an ordinary freestyle job it would be in the workspace).

Where has the uploaded file gone? Or do file parameters not currently work with pipelines?

like image 525
Daniel Butler Avatar asked Jun 28 '16 15:06

Daniel Butler


People also ask

How does file parameter work in Jenkins?

Jenkins provides a File parameter which allows a build to accept a file, to be submitted by the user when scheduling a new build. The file will be placed inside the workspace at the known location after the check-out/update is done so that your build scripts can use this file.


Video Answer


2 Answers

There is currently an issue with pipeline and file parameter (https://issues.jenkins-ci.org/browse/JENKINS-27413).

like image 112
AlexD Avatar answered Sep 16 '22 12:09

AlexD


Solved it the following way:

node {     deleteDir()     stage("upload") {         def inputFile = input message: 'Upload file', parameters: [file(name: 'data.zip')]         new hudson.FilePath(new File("$workspace/data.zip")).copyFrom(inputFile)         inputFile.delete()     }     stage("checkout") {         echo fileExists('data.zip').toString()     } } 

I know the solution is not that beautiful because the pipeline gets interrupted for the upload but it works.

Further the "copyFrom" is necessary, because the input stores the "data.zip" in the jobs directory and not in the workspace (don't know why)

like image 39
Christoph Forster Avatar answered Sep 16 '22 12:09

Christoph Forster