-
Task
-
Resolution: Unresolved
-
Minor
-
None
Given the following file in a shared library's vars folder
class acme implements Serializable { def script acme(script) {this.script = script} }
And the following snippet of Declarative code
stages { stage("Checking component sources and building snapshot") { steps { script { acme = new acme(this) } } } }
The end result is an error like
Unable to resolve class acme
To make this work I need to move the acme initialization out of the pipeline block like this
def acme = new acme(this) pipeline { .......
Although that is good to me as now the acme instance is available to all stages the current documentation does not mention anything related to this and I believe is worthwhile to add this case to the documentation.
[JENKINS-46918] Document how to use shared library's global classes in Declarative
Assignee | Original: Andrew Bayer [ abayer ] |
So...yeah. This isn't an ideal use case for Declarative, hence the lack of documentation. The libraries directive doesn't work well with classes, since the libraries get loaded after parsing/compilation of the Jenkinsfile in that case, while with @Library, the libraries are loaded during parsing/compilation of the Jenkinsfile.