Issue
I have configured a shared library and when using it on my pipeline, the builds failed and printed the following logs:
Loading library $SHARED_LIBRARY_NAME@TAG_VERSION Library $SHARED_LIBRARY_NAME@TAG_VERSION is cached. Copying from home. ERROR: Library $SHARED_LIBRARY_NAME expected to contain at least one of src or vars directories org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: Loading libraries failed Finished: FAILURE
Resolution
There are 2 different scenarios where the log ERROR: Library $SHARED_LIBRARY_NAME expected to contain at least one of src or vars directories
can be printed:
A) You are using a not valid shared library because it has not defined either a src
or vars
directory in the root of the repository.
B) You are facing a known issue detailed in JENKINS-69573. If that’s the case, this issue has been fixed in Pipeline: Groovy Libraries release 710.v4b_94b_077a_808. Therefore, you should upgrade your CloudBees CI to release 2.452.2.3 having previously enrolled your instance to CAP and under $JENKINS_URL/beekeeper/configuration/
you must enable Allow automatic upgrades of plugins on restart
.
Workaround
If you are facing the aforementioned known issue, but can’t upgrade your instance at the moment, there are 2 different temporary workarounds:
A) Reduce the refresh interval so that if the cache gets corrupted, it does not take long for the cache to be cleared without manual intervention to clear it.
B) If your CloudBees CI is 2.414.3 or higher (but lower than 2.452.2.3) you can manually upgrade your plugin Pipeline: Groovy Libraries to release 710.v4b_94b_077a_808. This approach is not recommended as you will need to upgrade and resolve all the plugin dependencies, which can cause unknown side effects as that leap is not tested under CAP.