Jenkins 管道: How to get the list of file from workspace?

标签 jenkins groovy parameters jenkins-pipeline

在 jenkinsfile 中,我想获取工作区目录中的文件列表并将它们放入参数中。 我尝试过:

stage('select'){
    def workspace = pwd()
    files = []
    new File  ("$workspace/buildFile").eachFile(FileType.FILES) { files << it.name }

    BuildFile = input( id: 'userInput', message: 'Sélectionner un backup', parameters: [ [$class: 'ChoiceParameterDefinition', choices: files , description: 'Properties', name: 'param'] ])   
}

但我收到消息错误“java.io.FileNotFoundException:”

最佳答案

问题在于管道脚本是在主服务器上执行的,因此当您执行new File(...)时,您会在主服务器而不是从服务器/节点/代理上创建文件指针工作区上下文。相反,您应该使用 findFiles可在 Pipeline Utility Steps plugin 中找到.

关于 Jenkins 管道: How to get the list of file from workspace?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45961623/

相关文章:

jenkins - 防止扩展 Jenkins 作业参数中的环境变量

c - 传递数组指针并打印

cocoa - cocoa /ARC-为什么将结构作为参数传递会导致对自动释放池的错误访问?

docker - Jenkins docker :command not found

linux - 如何使用 sudo 权限从 Jenkins 运行远程 ssh session ?

groovy - 如何在Groovy中列印java.library.path

java - Maven 项目找不到 Groovy 类

c++ - 形式参数列表不匹配

ssh - Jenkins - "Execute Shell"能否执行 SSH 命令

jenkins - 无法让 Jenkins Docker slave 构建 docker 镜像