Jenkins中缺少文件参数上传的文件 [英] file parameter uploaded file in Jenkins is missing

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

问题描述

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建议(多种方式):解决方案

在将文件参数与脚本化管道一起使用方面存在局限性,只是一个简单的自由式作业看起来很容易:

我现在要使用它&继续使用下游依赖项或类似方法来消耗上传的工件.

在此处输入图片描述

这样,它仅上传文件&请勿篡改文件大小&/它的内容:)

在可访问性方面,它是由${paramNameDefined}获取的.

在执行shell构建类型下,我们可以仅在上面的示例中放入${file1}来完成文件获取的技巧.

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

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

Per File Parameter 'help text' on Jenkins build,

Accepts a file submission from a browser as a build parameter. The uploaded file will be placed at the specified location in the workspace, which your build can then access and use. This is useful for many situations, such as:

  • Letting people run tests on the artifacts they built.
  • Automating the upload/release/deployment process by allowing the user to place the file.
  • Perform data processing by uploading a dataset.

The name of the submitted file is available in the environment variable whose name is the same as file location. For example, if you set the file location to be abc.zip, then ${abc.zip} would give you the original file name passed from the browser (such as my.zip.) The name will not include the directory name portion.

File upload is optional. If a user chooses not to upload anything, Jenkins will simply skips this parameter and will not place anything (but it also will not delete anything that's already in the workspace.)

And 'File location'

Specifies the location, relative in the workspace, where the uploaded file will be placed (for example, like "jaxb-ri/data.zip")

Simple upload of zip file per example tried - doesn't seem to upload file anywhere - Neither in Workspace , nor under some temp directory. How to locate the file &/ make use of it?.

Here is simple pipeline for attempt on file upload..

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
        '''
     }


}

And respective error on run as observed in Console log.

[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

Have tried Groovy suggestions per this (multiple ways) : Fetching binary or zipped uploaded files in Jenkins - Windows cannot open the folder . The Compressed(zipped) Folder is invalid , but no luck on making this work.

解决方案

With limitations around using file parameter with scripted pipeline, just a simple free-style job looks to do trick :( .

I am going with it for now & proceed with downstream dependency or similar on consuming uploaded artifacts.

enter image description here

With this it just uploads file & no tampering of file size &/ it's contents :)

Accessibility wise it is fetching by ${paramNameDefined}.

Under execute shell build type we can just put ${file1} for example above to do the trick of fetching file..

So here is output of running above free style job!

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆