2 min read | by Jordi Prats
To load a specific Jenkins Pipeline Shared Library we can use the @Library() function, but the library needs to be configured on Jenkins:
@Library('demo-shared-library') _
This is particularly annoying if:
If we want to load a library that it is stored on a git repository, we still load it:
library identifier: 'jordi-shared-library@v1',
retriever: modernSCM([
$class: 'GitSCMSource',
credentialsId: 'github-credentials',
remote: 'ssh://git@github.com:pet2cattle/jpl-clamscan.git'
])
This block of code allows us to define a name for the library and fetch a specific branch or tag, on this example v1:
library identifier: 'jordi-shared-library@v1',
We are also setting which credentials (that needs to be set on Jenkins) we want to use. If the repository is public we can skip this part:
credentialsId: 'github-credentials',
And finally, the URL of the repository itself, for example:
remote: 'ssh://git@github.com:pet2cattle/jpl-clamscan.git'
Posted on 13/01/2022