1

I have declarative pipeline used and have a problem to map key-value there as I can't use "def" within pipeline. I want to achieve something like this:

def pathTag = [:]
pathTag['myKey'] = 'myValue' 

I will use then "pathTag" later on as input for Jenkins plugin (Influxdb).

Has anyone idea how to do it? Thank you.

1 Answers1

1

There's two places you can use def and programatic Groovy Syntax:

  1. a script block, like script { def myvar = "I can only be seen in my script tag }
  2. Create a function outside the pipeline tag, like so:

    String hello(def who) {
      return "hi, ${who}"
    }
    
    pipeline {
      ...
    }
    

The function outside the pipeline block may break the graphical pipeline editor in Jenkins, but if you don't use that you're probably fine.

Source

RyanWilcox
  • 13,890
  • 1
  • 36
  • 60