[JIRA] [workflow-plugin] (JENKINS-27413) Handle file parameters

13 views
Skip to first unread message

yann@pleiades.fr.eu.org (JIRA)

unread,
May 28, 2015, 5:36:01 AM5/28/15
to jenkinsc...@googlegroups.com
Yann Rouillard commented on New Feature JENKINS-27413
 
Re: Handle file parameters

I am not sure I understand the issue's description but we do encounter a problem with workflow and file parameters.

We observe that the file parameter is not at all taken into account in the workflow parameter:

  • there is no environment variable defined at all concerning the parameter,
  • the file uploaded is not copied into the workflow workspace.

Which basically makes the file parameter completely useless for a job.
The same setup works for a standard job.

Are we are doing something wrong or is it a bug in the workflow plugin as this current issue seems to indicate ?

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.2#64017-sha1:e244265)
Atlassian logo

jglick@cloudbees.com (JIRA)

unread,
Aug 14, 2015, 9:01:01 AM8/14/15
to jenkinsc...@googlegroups.com
Jesse Glick commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Also need to check how we could send file parameters from a Workflow build, using the build step. Presumably you would want the actual file to come from the contextual workspace.

johan.warlander@kambi.com (JIRA)

unread,
Feb 24, 2016, 10:56:01 AM2/24/16
to jenkinsc...@googlegroups.com
Johan Wärlander commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Is there any way to work around this issue while keeping everything in a pipeline job?

I have a process where we run a job to pre-process some data, then save the result as an artifact; we then use the Promoted Builds plugin to indicate that the result was OK (after a manual review), and to trigger a second job to load that data using an ETL tool. The second job, then, has to use the Copy Artifact plugin.

While this works, it feels less direct than I'd like it to be; also, the user has to go to the second job to see the actual result of the ETL load.

j.r.hodgson@gmail.com (JIRA)

unread,
May 18, 2016, 4:12:02 AM5/18/16
to jenkinsc...@googlegroups.com
Jon Hodgson commented on New Feature JENKINS-27413
 
Re: Handle file parameters

I've just run into this issue, in fact I've run into it at an earlier level that the file just doesn't seem to be uploaded at all (you can't view it in the "parameters" page of the build, the file name and link are there, but clicking it gives an error rather than the file contents).

This is a major issue, because I need to set up try-before-commit functionality.

jglick@cloudbees.com (JIRA)

unread,
Aug 29, 2016, 1:44:06 PM8/29/16
to jenkinsc...@googlegroups.com
Jesse Glick updated an issue
 
Jenkins / New Feature JENKINS-27413
Handle file parameters
Change By: Jesse Glick
Component/s: pipeline-build-step-plugin
Component/s: workflow-cps-plugin
Component/s: pipeline
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

oren@chapo.co.il (JIRA)

unread,
Oct 25, 2016, 7:22:09 AM10/25/16
to jenkinsc...@googlegroups.com
Oren Chapo commented on New Feature JENKINS-27413
 
Re: Handle file parameters

I'm in the same boat with Jon Hodgson: trying to set up try-before-commit. All my jobs are pipelines, most of them are pretty complex so I can't go back to freestyle jobs... I'm stuck with missing file upload functionality.
For the sake of documentation, if someone knows of a workaround please post it here.

j.r.hodgson@gmail.com (JIRA)

unread,
Oct 25, 2016, 7:43:06 AM10/25/16
to jenkinsc...@googlegroups.com
Jon Hodgson commented on New Feature JENKINS-27413
 
Re: Handle file parameters

I bent over backwards trying to get it to work with string parameters, but between python (which I use for my launch script), Groovy and HTTP trying to be helpful something always got auto-converted (early tests would seem great, then I would try a real-world diff and there would be something in there that broke, such as accented characters in files that had different formats)

In the end I went with a smple FTP serverr on the same machine as Jenkins, and uploading a file with a name given by a job I pass as a string parameter.

It's not the most neat and tidy solution, but it works at least... well so far.

johan.warlander@kambi.com (JIRA)

unread,
Oct 31, 2016, 4:36:04 AM10/31/16
to jenkinsc...@googlegroups.com
Johan Wärlander commented on New Feature JENKINS-27413
 
Re: Handle file parameters

FYI, if you only need to deal with manual input.. file parameter can be caught in an 'input' step, and then passed on:

stage('file input') {
  node {
    // Get file using input step, will put it in build directory
    def inputFile = input message: 'Upload file', parameters: [file(name: 'data.txt')]
    // Read contents and write to workspace
    writeFile(file: 'data.txt', text: inputFile.readToString())
    // Stash it for use in a different part of the pipeline
    stash name: 'data', includes: 'data.txt'
  }
}

stage('do something with data') {
  node {
    // Unstash the file into an 'input' directory in the workspace
    dir('input') {
      unstash 'data'
    }
    // do something useful
    sh "ls -lR input/"
  }
}

Normally you would have the 'input' step outside of a node, but since we want to put our file in a workspace and stash (and / or archive) it, we'll need the node here.

geoffrey.arthaud@developpement-durable.gouv.fr (JIRA)

unread,
Nov 24, 2016, 2:39:04 AM11/24/16
to jenkinsc...@googlegroups.com
Geoffrey ARTHAUD commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Thank you Johan Wärlander for this solution which works well with text files. But I didn't find any simple solution for binary files, encoding parameter of writeFile is ignored (https://issues.jenkins-ci.org/browse/JENKINS-27094).

Here is one solution I've found, by using FilePath API directly :

Unable to find source-code formatter for language: groovy. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
stage('file input') {
  node('master') {
    def inputFile = input message: 'Upload file', parameters: [file(name: 'data.zip')]
    unzip dir: '', glob: '', zipFile: inputFile.remote
  }
}

But two drawbacks :

  • This works only on the master node (I didn't manage to access to the FilePath channel of the workspace from Pipeline plugin)
  • getRemote() method from FilePath is not whitelisted

Any suggestion ?

geoffrey.arthaud@developpement-durable.gouv.fr (JIRA)

unread,
Nov 24, 2016, 2:39:04 AM11/24/16
to jenkinsc...@googlegroups.com
Thank you Johan Wärlander for this solution which works well with text files. But I didn't find any simple solution for binary files, encoding parameter of writeFile is ignored (https://issues.jenkins-ci.org/browse/JENKINS-27094).

Here is one solution I've found, by using FilePath API directly :

{code: groovy java }

stage('file input') {
  node('master') {
    def inputFile = input message: 'Upload file', parameters: [file(name: 'data.zip')]
    unzip dir: '', glob: '', zipFile: inputFile.remote
  }
}
{code}

But two drawbacks :
* This works only on the master node (I didn't manage to access to the FilePath channel of the workspace from Pipeline plugin)
* getRemote() method from FilePath is not whitelisted

Any suggestion ?

geoffrey.arthaud@developpement-durable.gouv.fr (JIRA)

unread,
Nov 24, 2016, 2:42:03 AM11/24/16
to jenkinsc...@googlegroups.com
Geoffrey ARTHAUD edited a comment on New Feature JENKINS-27413
Thank you Johan Wärlander for this solution which works well with text files. But I didn't find any simple solution for binary files, encoding parameter of writeFile is ignored (https://issues.jenkins-ci.org/browse/JENKINS-27094).

Here is one solution I've found, by using FilePath API directly :

{code:java}

stage('file input') {
  node('master') {
    def inputFile = input message: 'Upload file', parameters: [file(name: 'data.zip')]
    unzip dir: '', glob: '', zipFile: inputFile.remote
  }
}
{code}

But two drawbacks :
* This works only on the master node (I didn't manage to access to the FilePath channel of the workspace from Pipeline plugin)
* getRemote() method from FilePath is not whitelisted

Using FilePath.copyTo() or FilePath.unzip() instead of unzip has similar drawbacks.

Any suggestion ?

johan.warlander@kambi.com (JIRA)

unread,
Nov 25, 2016, 5:26:05 AM11/25/16
to jenkinsc...@googlegroups.com
Johan Wärlander commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Geoffrey Arthaud, does Base64 encoding change anything in that scenario? Eg. something like:

writeFile(file: 'data.zip.b64', text: inputFile.read().getBytes().encodeBase64().toString())

..and then stash it, and do the decoding / unzipping it in a separate node section?

I don't know if it makes a difference w/ master vs slave node execution, as we only have a master node so far in our setup.

j.r.hodgson@gmail.com (JIRA)

unread,
Nov 25, 2016, 5:36:06 AM11/25/16
to jenkinsc...@googlegroups.com
Jon Hodgson commented on New Feature JENKINS-27413
 
Re: Handle file parameters

I personally gave up trying to pass the file as a parameter, as a text file it always got messed up somewhere along the line (it's a diff, so although it's text the encoding can vary depending on the source files).

So I siwtched to creating a zip with a uri as the filename, uploading it with ftp, and passing the uri as a parameter.

It's perhaps not as elegant as doing it all in jenkins, but it works.

geoffrey.arthaud@developpement-durable.gouv.fr (JIRA)

unread,
Nov 25, 2016, 10:35:06 AM11/25/16
to jenkinsc...@googlegroups.com
Geoffrey Arthaud commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Base64 encoding/decoding should do the trick on any master or slave node. Thank you !

burtsevyg@mail.ru (JIRA)

unread,
Mar 29, 2017, 7:03:04 AM3/29/17
to jenkinsc...@googlegroups.com
Yuriy Burtsev commented on New Feature JENKINS-27413
 
Re: Handle file parameters

"file parameter" and "stash" enough for load file to job running on different nodes.

This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

myxal.mxl@gmail.com (JIRA)

unread,
Apr 25, 2018, 9:25:04 AM4/25/18
to jenkinsc...@googlegroups.com
Michal Zatloukal commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Any news on this?

For the record, I noticed that the file provided through parameter is only missing when using Pipeline from SCM - when using Pipeline script, the file is present and this trivial pipeline completes successfully:


parameters {
  file description: 'Blah', name: 'custom.xml'
}
pipeline {
  agent any
  stages {
    stage ("cat-file") {
        steps {
            powershell 'Get-Content .\\custom.xml'
        }
    }
  }
}

csnyder@us.ibm.com (JIRA)

unread,
Aug 9, 2018, 8:00:13 AM8/9/18
to jenkinsc...@googlegroups.com
Chris Snyder commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Took a while to find out that this was an issue. Plus one for getting this fixed in an upcoming release. 

UnstashParam worked for me. Thanks.

This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

eygohlolz@gmail.com (JIRA)

unread,
Aug 14, 2018, 9:15:03 PM8/14/18
to jenkinsc...@googlegroups.com
Emmanuel Goh commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Can confirm that this is still broken - my minimal Jenkinsfile below yields "echo null":

 

pipeline {

  parameters {

    file(name: 'ZIP')

{{  }}}

  }}{{stages {

    stage('Test file') {

{{      steps { sh "echo ${params.ZIP}" }}}

{{    }}}

{{  }}}

}

eygohlolz@gmail.com (JIRA)

unread,
Aug 14, 2018, 9:16:03 PM8/14/18
to jenkinsc...@googlegroups.com
Can confirm that this is still broken - my minimal Jenkinsfile below yields "echo null":

 

{ { code:java}
pipeline { }}
  agent any
{{   parameters { }}

{{
    file(name: 'ZIP') }}

{{
  } }}

{{
  }}{{ stages { }}

{{
    stage('Test file') { }}

{{     
steps \ {
sh "echo ${params.ZIP}"
}
} }

{{   
} }}

{{ 
} }}

{ { code } }}

baurmatic@gmail.com (JIRA)

unread,
Oct 22, 2018, 6:15:04 AM10/22/18
to jenkinsc...@googlegroups.com
Bauyrzhan Makhambetov commented on New Feature JENKINS-27413
 
Re: Handle file parameters

 works in freesyle project but in pipeline is not working.

 
tried with `ls -l .` with no success, as if there is no file at all.

This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

jglick@cloudbees.com (JIRA)

unread,
Oct 24, 2018, 8:41:07 AM10/24/18
to jenkinsc...@googlegroups.com
Jesse Glick commented on New Feature JENKINS-27413
 
Re: Handle file parameters

File parameters are not currently supported. I am not particularly inclined to fix this per se since support for them is quite complicated architecturally—the implementation for freestyle projects does not generalize naturally and relies on a special file upload web request handler. Simpler, safer, and more flexible would be to introduce a plugin defining a Base64-encoded string parameter type, with a form submission GUI and CLI that make it convenient to obtain the value from a local file, as well as a SimpleBuildWrapper (usable as a Pipeline block-scoped step) that decodes the value to a local temporary file within its body.

jglick@cloudbees.com (JIRA)

unread,
Oct 24, 2018, 8:41:30 AM10/24/18
to jenkinsc...@googlegroups.com
Jesse Glick assigned an issue to Unassigned
Change By: Jesse Glick
Assignee: Jesse Glick

baurmatic@gmail.com (JIRA)

unread,
Oct 24, 2018, 4:01:13 PM10/24/18
to jenkinsc...@googlegroups.com
Bauyrzhan Makhambetov commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Thank you for pointing that out.

kuisathaverat@gmail.com (JIRA)

unread,
Mar 29, 2019, 6:39:25 AM3/29/19
to jenkinsc...@googlegroups.com
Ivan Fernandez Calvo edited a comment on New Feature JENKINS-27413
 
Re: Handle file parameters
my 5 cents, this code shows how to load a properties file into the environment, in the example the properties come from a String but also you can load a file from disk with the readProperties pipeline utility step

``` {code}
node {
   def configPrperties = """
   VAR01 = value1
   VAR02 = value2
   """
   def config = readProperties(text: configPrperties)
   config.each { k, v ->
       env."${k}" = v
   }
   sh 'export'
}
``` {code}

kuisathaverat@gmail.com (JIRA)

unread,
Mar 29, 2019, 6:39:25 AM3/29/19
to jenkinsc...@googlegroups.com

my 5 cents, this code shows how to load a properties file into the environment, in the example the properties come from a String but also you can load a file from disk with the readProperties pipeline utility step

```


node {
def configPrperties = """
VAR01 = value1
VAR02 = value2
"""
def config = readProperties(text: configPrperties)
config.each { k, v ->
env."${k}" = v
}
sh 'export'
}
```

alexhaynes93@gmail.com (JIRA)

unread,
May 2, 2019, 3:29:26 PM5/2/19
to jenkinsc...@googlegroups.com
Alex Haynes commented on New Feature JENKINS-27413
 
Re: Handle file parameters

If there is no plan to support the file parameter option, it would be nice to remove it from the documentation here: https://jenkins.io/doc/book/pipeline/syntax/#parameters

jglick@cloudbees.com (JIRA)

unread,
May 2, 2019, 5:47:10 PM5/2/19
to jenkinsc...@googlegroups.com

james.hogarth@gmail.com (JIRA)

unread,
May 3, 2019, 5:33:04 AM5/3/19
to jenkinsc...@googlegroups.com
James Hogarth commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Avoid actively breaking it though please as as we do actually use this functionality with the help of our global library. 

james.hogarth@gmail.com (JIRA)

unread,
May 3, 2019, 5:38:05 AM5/3/19
to jenkinsc...@googlegroups.com
Avoid actively breaking it though please as as we do actually use this functionality with the help of our global library. 


 
{code:java}
def inputGetFile(String savedfile = null) {
def filedata = null
def filename = null

// Get file using input step, will put it in build directory
// the filename will not be included in the upload data, so optionally allow it to be specified
if (savedfile == null) {
def inputFile = input message: 'Upload file', parameters: [file(name: 'library_data_upload'), string(name: 'filename', defaultValue: 'uploaded-file-data')]
filedata = inputFile['library_data_upload']
filename = inputFile['filename']
} else {
def inputFile = input message: 'Upload file', parameters: [file(name: 'library_data_upload')]
filedata = inputFile
filename = savedfile

}
// Read contents and write to workspace
writeFile(file: filename, encoding: 'Base64', text: filedata.read().getBytes().encodeBase64().toString())
// Remove the file from the master to avoid stuff like secret leakage
filedata.delete()
return filename
}{code}
And this library code is used with this jenkinsfile snippet:
{code:java}
stage('request a file with chosen filename') {
node {
deleteDir()
uploaded_file = library.inputGetFile('my-file-here')
sh "file '${uploaded_file}'"
sh "ls -la ."
}
}{code}
 

 

jglick@cloudbees.com (JIRA)

unread,
Jun 21, 2019, 3:19:13 PM6/21/19
to jenkinsc...@googlegroups.com
Jesse Glick commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Another plugin idea, useful for uploads too large to be reasonably handled as Base64 and environment variables: a parameter type which lets you upload a file to an S3 (or MinIO) bucket. Could either upload from the master upon form/CLI submission; or, more efficiently, provide a special UI & API endpoint to allocate a blob and then hand you a presigned URL good for upload only, valid for an hour. The parameter value would be a presigned URL good for download only, again valid only for a day or so. Similarly for Azure etc.

(No need to delete the blob in a RunListener after the build completes. That would break Replay / Rebuild and, as with artifact-manager-s3, would force the master to have a more dangerous IAM permission. Anyway S3 can be configured to automatically expunge or archive old blobs.)

cfrolik@gmail.com (JIRA)

unread,
Jun 26, 2019, 1:19:06 PM6/26/19
to jenkinsc...@googlegroups.com
Chris Frolik commented on New Feature JENKINS-27413
 
Re: Handle file parameters

"I am not particularly inclined to fix this per se"

That is very disappointing, and a stumbling block for those trying to convert their freestyle jobs to declarative pipeline jobs. I really hope you change your mind on this.

At the very least, the documentation should mention that it isn't supported.

cfrolik@gmail.com (JIRA)

unread,
Jun 26, 2019, 1:19:11 PM6/26/19
to jenkinsc...@googlegroups.com
Chris Frolik edited a comment on New Feature JENKINS-27413
 
Re: Handle file parameters
{quote} "I am not particularly inclined to fix this per se"
{quote}
That is very disappointing, and a stumbling block for those trying to convert their freestyle jobs to declarative pipeline jobs. I really hope you change your mind on this.

At the very least, the documentation should mention that it isn't supported.

mark.earl.waite@gmail.com (JIRA)

unread,
Jul 25, 2019, 12:43:11 PM7/25/19
to jenkinsc...@googlegroups.com
Mark Waite commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Removed from documentation on jenkins.io July 25, 2019 by PR-2388

jan.vrany@fit.cvut.cz (JIRA)

unread,
Oct 1, 2019, 6:02:04 PM10/1/19
to jenkinsc...@googlegroups.com
Jan Vrany commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Just a notice:
I have moved my workaround library with `unstashParam` step to GitHub, new locations is

https://github.com/janvrany/jenkinsci-unstashParam-library

I also renamed it as this issue seems to be unlikely "fixed".

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

reach.vinay.av01@gmail.com (JIRA)

unread,
Dec 27, 2019, 7:13:05 AM12/27/19
to jenkinsc...@googlegroups.com
Vin Win commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Hi James Hogarth - Does the solution works for binary/zip file. Tried using groovy script & respective one on Jenkins pipleline, but it doesn't seem to work for zip (Can not open file 'fileName.zip' as archive') or binary file uploaded. Would like to know if this is been considered in future releases ?

paul.sharpe@zf.com (JIRA)

unread,
Jan 2, 2020, 3:00:22 AM1/2/20
to jenkinsc...@googlegroups.com
Paul Sharpe commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Vin Win: The unstashParam workaround works great for us, including zip files. We are using a windows instance of Jenkins (in case that is significant).

andreas.schmid@bd.so.ch (JIRA)

unread,
Jan 27, 2020, 3:14:04 AM1/27/20
to jenkinsc...@googlegroups.com
Andreas Schmid commented on New Feature JENKINS-27413
 
Re: Handle file parameters

I don't quite understand if this is just not implemented yet, or if it's impossible to implement at all. If it is possible, we might be able to fund the development of this feature, as we need it too. As I am still rather new to the Jenkins community: Can anyone recommend me any companies that could do that?

 

jglick@cloudbees.com (JIRA)

unread,
Jan 27, 2020, 9:28:22 AM1/27/20
to jenkinsc...@googlegroups.com
Jesse Glick commented on New Feature JENKINS-27413
 
Re: Handle file parameters

Andreas Schmid as to technical design, see my comments of 2018-10-24 and 2019-06-21. I am interpreting the requirement more broadly than the original statement: a user or script should be able to trigger a Pipeline job with a build parameter that includes the contents of a (possibly large, possibly binary, but not secret) file, using any common mechanism (GUI, HTTP POST, build-job CLI command, build step), in such a way that some convenient (Scripted and/or Declarative) syntax may be used to retrieve that file in a designated workspace location at a designated time, including in future rebuilds.

Reply all
Reply to author
Forward
0 new messages