ImranRazaKhan
ImranRazaKhan

Reputation: 2297

groovy.lang.MissingPropertyException: No such property: CHANGE_author

I am getting following error and my scripts is like below

pipeline {
    agent any

    stages {
         stage('Build') {
            steps {
                echo 'I am building '+scm.branches[0].name+' branch.'
                sh "echo Shell ${CHANGE_author}"
                echo "echo Shell ${CHANGE_author}"
            }
        }
    }
}

Following is error trace

groovy.lang.MissingPropertyException: No such property: CHANGE_author for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:242)
    at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:268)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)

As per documentations expert from link https://jenkins.io/doc/book/pipeline/syntax/

"changeRequest" Executes the stage if the current build is for a "change request" (a.k.a. Pull Request on GitHub and Bitbucket, Merge Request on GitLab or Change in Gerrit etc.). When no parameters are passed the stage runs on every change request, for example: when { changeRequest() }. By adding a filter attribute with parameter to the change request, the stage can be made to run only on matching change requests. Possible attributes are id, target, branch, fork, url, title, author, authorDisplayName, and authorEmail. Each of these corresponds to a CHANGE_ environment variable, for example: when { changeRequest target: 'master' }."*

So i can access environment variables as CHANGE_*, but its not working

Upvotes: 0

Views: 2743

Answers (1)

ParthaSarathi
ParthaSarathi

Reputation: 69

If you have defined environment variable as CHANGE_author in your Jenkins server, try using env.CHANGE_author to access it.For example:

    stage('Example1') {
       steps {
           script{
                env.int_param1 = '2'
           }
       }
    }
    stage('Example2') {
         steps {
             echo "${env.int_param1}"
         }
    }

Upvotes: 1

Related Questions