In-tree Groovy script libraries

So I’m in the process of creating a monorepo for a new client where all code and configuration is hosted next to each other. The client already has an extensive Groovy script library that I want to utilize as-is for my new build setup.

What I fail to see however is a straightforward way of including a script library as-source on top of a Jenkinsfile. I could probably work around this by giving the @Library annotation a GitScmSource that would point to the local (already checked out) Git repository, but this somehow seems to be a hacky approach.

Is there any better way to include a Jenkins script library source-only from the currently checked-out Git workspace?

Thanks!
Thomas.

Ah, now that I think of it (I have been away from Jenkins for a few years) - I forgot that Jenkins has no default check out at the start of the pipeline. So the question is rather, how do I pin-point to the exact same revision that I’m currently building, by using the exact same repo. To keep this self-contained, I’d really like to have no central configuration in Jenkins itself, so I’d define the GitScmSource in my root level Jenkinsfile.

After reading through a couple of lengthy pull requests and tickets I guess the way to go is to use the legacyScm with the relatively new libraryPath argument which should apparently do the trick:

library(identifier: 'some-identifier@unused', retriever: legacySCM(scm: scm, libraryPath: 'path/to/jenkins/lib'))

Let’s see how this works.