Jenkins 管道将所有参数转换为小写

Sai*_*Sai 5 parameters groovy jenkins-groovy jenkins-pipeline

如何将 Jenkins 管道中的所有参数转换为小写。类似于trim,是否有一个属性可以作为参数声明的一部分添加,

对于修剪,我有如下内容,

parameters {
   string defaultValue: '', description: 'Some dummy parameter', name: 'someparameter', trim: true
}
Run Code Online (Sandbox Code Playgroud)

在我的管道工作中,我有 10 多个字符串参数,并希望将它们全部转换为小写

小智 8

sh """ ${the_parameter.toLowerCase()} """
Run Code Online (Sandbox Code Playgroud)
  1. 需要使用双引号,这样你就有了一个 GString
  2. toLowerCase()函数调用放在大括号内,以便 shell 引用回 groovy


Ric*_*can 7

这是一种方法:

pipeline {
    agent any
    parameters {
        string ( name: 'testName', description: 'name of the test to run')
    }
    stages {
        stage('only') {
            environment {
                TEST_NAME=params.testName.toLowerCase()
            }
            steps {
                echo "the name of the test to run is: ${params.testName}"
                sh 'echo "In Lower Case the test name is: ${TEST_NAME}"'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)