Jenkins pipeline convert all parameters to lowercase

Viewed 17819

How can I convert all the parameters in a Jenkins pipeline to lowercase. Similar to trim, is there an attribute that one could add as part of the parameter declaration,

For trim, I have something like below,

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

In my pipeline job, I have more than 10 string parameters and would like to convert them all to lowercase

3 Answers

Here's one approach:

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}"'
            }
        }
    }
}
sh """ ${the_parameter.toLowerCase()} """
  1. Need to use double quote so you have a GString
  2. Put the toLowerCase() function call inside the brace for shell to refer back to groovy

Actually one can just do

VAR = "${VAR.toLowerCase()}"
Related