I have a jenkinsfile which call shared library at the beginning
@Library('gconftools') import forjenkins.GetNodes
this jenkinsfile work correctly, but when I want to test with declarative-linter, there is an error.
java -jar /var/lib/jenkins/home/war/WEB-INF/jenkins-cli.jar -s http://serveur.domainperso:8082 declarative-linter --username=user --password mdp <script.groovy Errors encountered validating Jenkinsfile: WorkflowScript: 7: unable to resolve class forjenkins.GetNodes @ line 7, column 1. @Library('gconftools') ^ WorkflowScript: 26: unable to resolve class forjenkins.GetNodes @ line 26, column 7. z = new forjenkins.GetNodes() ^
First, I'd suggest upgrading to Declarative 1.1 and using the new libraries directive -
pipeline { agent any libraries { lib('gconftools') } stages { ... } }
And then let me know if that works, and if not, what the error is along with (ideally) a copy of the Jenkinsfile having the problem.
hi,
I don't see any doc for this new libraries directive.
do you have a working example?
thank
I have found the doc (https://jenkins.io/doc/book/pipeline/shared-libraries/#loading-libraries-dynamically ), and resolved my problem . So you can close this bug.
Raul Arabaolaza Did you try that code ? because it returns the same error as Matthew Mitchell !
Did someone figured out this error ?
The workaround of Raul Arabaolaza is working for me. Instantiating the object before it is used inside the shared library itself.
So something like
def lib = library("libs") def o = lib.com.package.classA.new() customStep() // step which is defined in "lib" and also instantiates classA o.method()
works, while something like
def lib = library("libs") customStep() // step which is defined in "lib" and instantiates classA lib.com.package.classA.new().method()
does not