I would like to use the "input step" of Jenkins to upload a binary file to the current workspace.
However, the code below seems to upload the file to the Jenkins master, not to the workspace of the current job on the slave where the job is running. Is there any way to fix that?
Preferably without having to add an executor on the master or clutter the master disk with files.
def inFile = input id: 'file1', message: 'Upload a file', parameters: [file(name: 'data.tmp', description: 'Choose a file')]
Seems Jenkins officially doesn't support upload of binary file yet as you can see in JENKINS-27413. You can still make use of the
input
step to get binary file in your workspace. We will be using a method to get this working but we will not use it inside theJenkinsfile
otherwise we will encounter errors related toIn-process Script Approval
. Instead, we will use Global Shared Libraries, which is considered one of Jenkins' best practices.Please follow these steps:
1) Create a shared library
vars
in above repository. Insidevars
directory, create a filecopy_bin_to_wksp.groovy
with the following content:2) Configure Jenkins for accessing Shared Library in any pipeline job
3) Access shared library in your job
Jenkinsfile
, add the following code:You're all set to run the job. :)
Note:
Code Reference: James Hogarth's comment