Issue
- How can I upload a file in a Pipeline?
Environment
- CloudBees Core on modern cloud platforms - Managed Master
- CloudBees Core on traditional platforms - Client Master
- CloudBees Jenkins Enterprise - Managed Master
- CloudBees Jenkins Platform - Client Master
- CloudBees Jenkins Distribution
- Jenkins LTS
Resolution
Waiting for JENKINS-27413 to be fixed, uploading a file in a Pipeline involves manually copying the file from the master to the agent.
The following sample will:
* ask the end user for the file (it is assumed that it is an archive)
* copy it on the agent
* prove that the file is visible on the agent
* archive it back to the master
// assuming you wish to upload a zip archive
def uploadedFile = 'uploaded.zip'
//file is uploaded to $JENKINS_HOME/$PATH_TO_THE_JOB/build/$BUILD_ID
def masterFilePath = input message: 'Upload your archive', parameters: [file(description: 'archive', name: uploadedFile)]
node('agent') {
stage('Copy From Master') {
def localFile = getContext(hudson.FilePath).child(uploadedFile)
localFile.copyFrom(masterFilePath)
sh 'ls -al'
archiveArtifacts uploadedFile
}
}
Note that, for this to work you will have to approve two methods in the script approval screen.
Tested product/plugin versions
- Jenkins 2.190
0 Comments