file parameter in declarative pipeline

Imr*_*han 5 jenkins jenkins-pipeline jenkins-declarative-pipeline

我正在开发声明式管道,并希望使用文件参数来读取其内容,但它没有按预期工作

parameters{
        file(fileLocation:'list.txt', description:'contains list of projects to be build')
   }
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 12: Invalid parameter "fileLocation", did you mean "description"? @ line 12, column 14.
           file(fileLocation:'release-list.txt', description:'contains list of projects to be build')
Run Code Online (Sandbox Code Playgroud)

以下是基本步骤插件提到的另一个选项

readFile: Read file from workspace
Reads a file from a relative path (with root in current directory, usually workspace) and returns its content as a plain string.
file
Relative ( /-separated) path to file within a workspace to read.
Type: String
encoding (optional)
Type: String
Run Code Online (Sandbox Code Playgroud)

它在脚本步骤中工作就像

def myfile = readFile('list.txt')
echo "${myfile}"
Run Code Online (Sandbox Code Playgroud)

但是如何像我们使用 dir 这样的其他基本步骤一样直接在声明性脚本中使用它?

Imr*_*han 0

以下语法有效

parameters{
        file name:'list.txt', description:'contains list of projects to be build'
   }
Run Code Online (Sandbox Code Playgroud)

但 fileLocation 参数仍然不可接受。

Jenkins2 Up & Running 书中提供了以下语法,但它不起作用

parameters{
        file(fileLocation:'list.txt', description:'contains list of projects to be build')
   }
Run Code Online (Sandbox Code Playgroud)