@Hernan & @Allan that does not work in declarative pipeline.
I also tried
pipeline {
stages {
stage("Build"){
steps {
script {
env.currentBuild.displayName = "The name."
env.currentBuild.description = "The best description."
}
... do whatever.
}
}
}
}
But it throws NullPointerException error as shown below
java.lang.NullPointerException: Cannot set property 'displayname' on null object
at org.codehaus.groovy.runtime.NullObject.setProperty(NullObject.java:80)
at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:197)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:484)
at org.kohsuke.groovy.sandbox.impl.Checker$7.call(Checker.java:347)
Comments
6 comments
Actually it changes the build description not build name, so the post title can be confusing. Resolution is currentBuild.displayName
We will update the article with the changes.
What is the equivalent for this in a declarative pipeline?
Hernán
In declarative you must use the script { ... } block.
@Hernan & @Allan that does not work in declarative pipeline.
I also tried
@Badal My script is missing the `agent` directive, the following should work as is:
If it does not, please file a support request so that we can troubleshoot this further.
Note:
currentBuild
is a Groovy variable, not an environment variable. So you cannot useenv.
Please sign in to leave a comment.