Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline convert all parameters to lowercase

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

like image 686
Sai Avatar asked Jun 29 '19 17:06

Sai


2 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}"'
            }
        }
    }
}
like image 122
Rich Duncan Avatar answered Oct 09 '22 20:10

Rich Duncan


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
like image 24
Jacccck Avatar answered Oct 09 '22 19:10

Jacccck