0

Here is the structure of my pipeline:

def call(String microservice_param) {

pipeline {
    environment {
        MICROSERVICE_NAME = "${microservice_param}".split("-")[1]
    }
}

I would like to manipulate the string parameter as shown above but I get this error: Environment variable values can only be joined together with ‘+’s.

Is there a way to do this?

  • Have you seen [this](https://stackoverflow.com/questions/11257014/to-get-substring-in-groovy-separated-by-a-character) – John Sep 20 '18 at 22:33

1 Answers1

0

While I don't like my own solution, it does work: define a new variable and set it prior to your pipeline block and use it in your environment.

def call(String microservice_param) {
  def microserv_name = microservice_param.split("-")[1]
  pipeline {
    environment {
    MICROSERVICE_NAME = "${microserv_name}"
    }
  .
  .
  .
  }
}

Haven't found a better solution - perhaps someone will provide it here. Assuming you would be using more of the parameters, you'd create a new variable for each and use it in the Environment directive. We do this for use in shared library declarative pipeline code, but use a Map for the call parameter.

John
  • 453
  • 3
  • 12