Home > Software engineering >  Jenkins all build parameters(key and value) concatenation as single string
Jenkins all build parameters(key and value) concatenation as single string

Time:09-27

I am creating a jenkins-pipeline which will concatenate all build params as single string (as we need this in cURL api call as a shell argument)

pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        script {
          for (entry in params) {
            echo "Build param: ${entry.key} - ${entry.value}"
          }
        }
      }
    }
  }
}

Could you please help me to concatenate all params as single string ==> "param1=value1&param2=value&param3=value3&..." etc.

CodePudding user response:

In order to retrieve key and value of the parameters you will need to use getKey() and getValue() functions. For string concatenation I used operator.

pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        script {
          def curl = ""
          for (entry in params) {
            curl  = entry.getKey()   "="   entry.getValue()   "&"
          }
        }
      }
    }
  }
}

Groovy Strings

  • Related