首页 > 解决方案 > Jenkins 管道将所有参数转换为小写

问题描述

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

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

parameters {
   string defaultValue: '', description: 'Some dummy parameter', name: 'someparameter', trim: true
}

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

标签: groovyparametersjenkins-pipelinejenkins-groovy

解决方案


这是一种方法:

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}"'
            }
        }
    }
}

推荐阅读