本文介绍了在Jenkins中获取上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Upload (per progress bottom bar status) goes through in Jenkins. But don't see option to locate or fetch uploaded file from Jenkins.

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

Here is simple script with File parameters,

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输入文件选项,但是没有运气到达上传的文件.有输入吗?

Tried with def input file option per other post, but no luck of reaching uploaded file. Any inputs?

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

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

With scripted full pipeline pasted above, getting below error..

[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

推荐答案

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

但是,有一个具有解决方法的库可以帮助您 https://github.com /janvrany/jenkinsci-unstashParam-library .如自述文件所述,您可以将此库添加到您的Jenkins(使用共享库扩展),并按以下方式使用它:

There is however a library with a workaround that can help you https://github.com/janvrany/jenkinsci-unstashParam-library. As described in the readme you can add this library to your Jenkins (Extending with Shared Libraries) and use it the following way:

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

这篇关于在Jenkins中获取上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 21:21