如何从 Jenkins 声明性管道中的文本参数检索所有行?

How to retrieve all lines from a text parameter in a Jenkins declarative pipeline?

我的 jenkinsFile 中有一个文本参数供 Jenkins 管道作业使用。此文本参数用于输入文件名列表(每行一个)。

奇怪的是,当我打印构建环境变量时,似乎只检测到文本字段第一行的值。

詹金斯文件

pipeline {
        agent any
        
        parameters {
            
            text(
                    name: 'FILE_LIST', 
                    defaultValue: '', 
                    description: 'File list'
            )
        }
        
        stages {

            stage("Environnement variables") {
                steps {
                    sh 'printenv | grep FILE_LIST'
                }
            }
        }
}

文本字段的内容示例

test.sql
MY_TEST.SQL
test_01.sql

结果

FILE_LIST=test.sql

如何从 Jenkins 管道中的文本参数访问所有行的值?

如果你想得到这样的东西“printenv | grep file1 file2”使用下面的代码

pipeline {
    agent any
    
    parameters {
        
        text(
                name: 'FILE_LIST', 
                defaultValue: '', 
                description: 'File list'
        )
    }
    
    stages {

        stage("Environnement variables") {
            steps {
                script{
                    String fllist=FILE_LIST.split("\r?\n").join(' ')
                    echo fllist
                     
                    sh 'printenv | grep $fllist'
                
                }
            }
        }
    }

}