Jenkins中的文件参数上传文件丢失

问题描述 投票:0回答:2

[Jenkins构建上的每个文件参数'帮助文本',

接受来自浏览器的文件提交作为构建参数。上载的文件将放置在工作区中的指定位置,然后您的构建可以访问和使用该文件。这在许多情况下很有用,例如:

  • 让人们对其构建的工件进行测试。
  • 通过允许用户放置文件来自动执行上载/发布/部署过程。
  • 通过上传数据集执行数据处理。

提交文件的名称在环境变量中可用,该变量的名称与文件位置相同。例如,如果将文件位置设置为abc.zip,则$ {abc.zip}将为您提供从浏览器传递的原始文件名(例如my.zip)。该名称将不包括目录名部分。

文件上传是可选的。如果用户选择不上传任何内容,Jenkins只会跳过此参数并且不会放置任何内容(但它也不会删除工作空间中已经存在的任何内容。)

和'文件位置'

[指定相对于工作空间的相对位置,在该位置将放置上传的文件(例如,像“ jaxb-ri / data.zip”)]

尝试每个示例简单地上传zip文件-似乎没有在任何地方上传文件-既不在Workspace中,也不在某些temp目录下。如何找到文件和/或使用它?。

这里是用于尝试上传文件的简单管道。

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

node {
    stage("Upload File") {
        sh '''
        ls -lrt
        ls  ${file1.zip} ${file1} file1.zip
        '''
     }


}

以及在控制台日志中观察到的相应运行错误。

[Pipeline] {
[Pipeline] stage
[Pipeline] { (Upload File)
[Pipeline] sh
[testSh] Running shell script
+ ls -lrt
total 0
Workspacedir///testSh@tmp/durable-ba40512f/script.sh: line 4: ${file1.zip}: bad substitution
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

已经尝试过这种Groovy建议(多种方式):Fetching binary or zipped uploaded files in Jenkins - Windows cannot open the folder . The Compressed(zipped) Folder is invalid,但运气不好。

jenkins groovy file-upload jenkins-pipeline binaryfiles
2个回答
0
投票

由于在脚本化管道中使用文件参数有一定的局限性,只是一个简单的自由式作业看起来很容易:(。

我现在要使用它,并继续进行下游依赖性或类似的消耗上载工件的过程。

enter image description here

有了它,它仅上传文件,而不会篡改文件大小和//它的内容:)

明智地使用${paramNameDefined}进行访问。

在执行shell构建类型下,我们可以仅在上面输入${file1}以完成文件提取的技巧。

所以这是运行以上自由样式作业的输出!

Copying file to file1
[sharedspace] $ /bin/sh -xe /tmp/hudson3237344085461334672.sh
+ ls file1.zip
file1.zip
Finished: SUCCESS

0
投票

问题Jenkins Pipeline Job with file parameter已经提供了此问题的答案。

new hudson.FilePath(new File("file1.zip")).copyFrom(file1)
file1.delete()
© www.soinside.com 2019 - 2024. All rights reserved.