在 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/