Details

    • Similar Issues:

      Description

      JENKINS-27295 discusses getting values from various kinds of parameters. Handling FileParameterValue is another matter. buildEnvironment (what is called today) is useless since it gives only a file name. createBuildWrapper is the way this works in a freestyle project, but this cannot work in a workflow; even if it were to return a SimpleBuildWrapper (JENKINS-24673) it is not clear where that would be called, since we can only use it from a workspace. getValue as currently implemented is useless since a FileItem does not have whitelisted methods, and anyway we would not want the flow itself to be copying streams to the workspace; this needs to be done by infrastructure. The only way forward I can see at the moment is for getValue to return a SimpleBuildWrapper, so that your flow could read

      node {
        wrap([$delegate: parameters.myFileParam]) {
          sh 'cat myFileParam'
        }
      }
      

        Attachments

          Issue Links

            Activity

            Hide
            jglick Jesse Glick added a comment -

            Alex Haynes good point! You can help.

            Show
            jglick Jesse Glick added a comment - Alex Haynes good point! You can help .
            Hide
            hogarthj James Hogarth added a comment - - edited

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

             

            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
            }

            And this library code is used with this jenkinsfile snippet:

            stage('request a file with chosen filename') {
             node {
             deleteDir()
             uploaded_file = library.inputGetFile('my-file-here')
             sh "file '${uploaded_file}'"
             sh "ls -la ."
             }
            }

             

             

            Show
            hogarthj James Hogarth added a comment - - edited Avoid actively breaking it though please as as we do actually use this functionality with the help of our global library.    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 } And this library code is used with this jenkinsfile snippet: stage( 'request a file with chosen filename' ) { node { deleteDir() uploaded_file = library.inputGetFile( 'my-file-here' ) sh "file '${uploaded_file}' " sh "ls -la ." } }    
            Hide
            jglick Jesse Glick added a comment -

            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.)

            Show
            jglick Jesse Glick added a comment - 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.)
            Hide
            fr0 Chris Frolik added a comment - - edited

            "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.

            Show
            fr0 Chris Frolik added a comment - - edited "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.
            Hide
            markewaite Mark Waite added a comment -

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

            Show
            markewaite Mark Waite added a comment - Removed from documentation on jenkins.io July 25, 2019 by PR-2388

              People

              • Assignee:
                Unassigned
                Reporter:
                jglick Jesse Glick
              • Votes:
                95 Vote for this issue
                Watchers:
                102 Start watching this issue

                Dates

                • Created:
                  Updated: