在Jenkins中获取上传的文件

时间:2019-12-24 11:55:27

标签: file jenkins file-upload parameters jenkins-pipeline

在Jenkins中完成上传(每个进度的底部栏状态)。但是看不到从詹金斯定位或获取上传文件的选项。

这是带有File参数的简单脚本,

properties(
    [
        parameters(
            [ file(name: "file1.zip", description: 'Choose path to upload file1.zip from local system.'),
              file(name: "file2.zip", description: 'Choose path to upload file2.zip from local system.') ]
            )
    ]
)

node {
    stage("Fetch Uploaded File") {
        sh '''
        ls -l file1.zip file2.zip
        ls -l ${WORKSPACE}/file1.zip ${WORKSPACE}/file2.zip
        '''
     }


}

每隔一个帖子都尝试了def输入文件选项,但是没有运气可以上传文件。有输入吗?

    def inputFile = input message: 'Upload file', parameters: [file(name: 'data.ear')]
    new hudson.FilePath(new File("$workspace/data.ear")).copyFrom(inputFile)
    inputFile.delete()

在上面粘贴了脚本化的完整管道,得到以下错误。

[Pipeline] {
[Pipeline] stage
[Pipeline] { (Fetch Uploaded File)
[Pipeline] sh
[testSh] Running shell script
+ ls -l file1.zip file2.zip
ls: cannot access file1.zip: No such file or directory
ls: cannot access file2.zip: No such file or directory
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 2
Finished: FAILURE

1 个答案:

答案 0 :(得分:0)

这是一个已知的错误JENKINS-27413

但是,有一个具有解决方法的库可以为您https://github.com/janvrany/jenkinsci-unstashParam-library提供帮助。如自述文件所述,您可以将此库添加到Jenkins(Extending with Shared Libraries)中,并按以下方式使用它:

library "jenkinsci-unstashParam-library"
node {
   def file_in_workspace = unstashParam "file"
   sh "cat ${file_in_workspace}"
}