Jenkinsfile sh (shell) 步骤中的全局模式

Glob patterns in Jenkinsfile sh (shell) steps

我正在尝试为 运行 我们的 CI 管道设置 Jenkinsfile。其中一个步骤将涉及从我们的目录树中收集文件并将它们复制到一个目录中,以便压缩。

我正在尝试使用 Jenkins sh 步骤并使用 glob 模式来执行此操作,但我似乎无法让它工作。

一个简单的例子 Jenkinsfile 是:

pipeline {
    agent any
    stages {
        stage('List with Glob'){
            steps{
                sh 'ls **/*.xml'
            }
        }
    }
}

期望列出工作区中的任何 .xml 文件,但我收到:

[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (List with Glob)
[Pipeline] sh
[jenkinsfile-pipeline] Running shell script
+ ls '**/*.xml'
ls: cannot access **/*.xml: No such file or directory
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 2
Finished: FAILURE

我想我在 Groovy 字符串插值中遗漏了一些东西,但我需要一些帮助来解决这个特定的问题(运行通过 Jenkinsfile 在 Jenkins 管道中使用)

非常感谢任何帮助!

据我所知 **/*.xml' 不是有效的 glob 模式 (see this). Instead what you have there is an ant naming pattern, which, as far as I know, isn't supported by bash (or sh). Instead what you wan't to do is to use find:

pipeline {
    agent any
    stages {
        stage('List with find'){
            steps{
                sh "find . -type f -name '*.xml'"
            }
        }
    }
}