0

I need to update my build param in declarative pipeline script, I tried:

pipeline {
    stages {
        stage {
            steps {
                script {
                    def reporter = build.buildVariableResolver.resolve("reporter")
                    if (reporter != null) {
                        reporter = reporter.tokenize(',').find {item -> item.contains('displayName')}.tokenize('=')[1]
                    } else {
                      reporter = ""
                    }
                    def reporterParameter = new StringParameterValue("reporter", "\${reporter}")
                    build.addOrReplaceAction(new ParametersAction(reporterParameter))
                }
            }
        }
    }
}

but I get error hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: build for class: WorkflowScript How can I run this groovy script in declarative pipeline or upadate my build params in another way (but declaratively)

3
  • Did you check this : stackoverflow.com/a/19564602/7953086 I think you are using the Jenkins v1.x syntax. Commented Sep 2, 2021 at 13:32
  • Sorry, I can't see the answer to my question there. I think this is problem I'm trying execute groovy script in declarative section and there cannnot be found specific classes and their methods Commented Sep 2, 2021 at 13:47
  • But what you want to achieve is to set a parameter on the fly during a step ? I think you are using an old syntax, maybe you can perform it using this : stackoverflow.com/a/57411391/7953086 Commented Sep 2, 2021 at 14:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.