0

I have a Jenkins declarative pipeline wherein I am trying to store the value returned from a method into environment variable as shown below.

steps {
                
                script {
                    
                    def job = getJob(JOB_NAME)
                    def param = getParam(job, "Ser")
                    echo param.getValue()
                }
                
                
            }
            environment {
                p_values = param.getValue()
            }

But while running above script I am getting below error.

java.lang.IllegalArgumentException: One or more variables have some issues with their values: p_values

Could you please assist me here to resolve this issue?

svw1105
  • 127
  • 1
  • 15

1 Answers1

1

I think the environment block will be executed prior to the script block.

You can try assign value to an new environment variable within script block, rather then in environment block as following:

script {          
  def job = getJob(JOB_NAME)
  def param = getParam(job, "Ser")
  echo param.getValue()
  env.p_values = param.getValue()
}
yong
  • 13,357
  • 1
  • 16
  • 27