How can a Jenkins Global Pipeline Library, which can be configured in the Jenkins master, be set up using Groovy code?
Derived from the great answer of StephenKing, here is the new way to do for the ModernSCM using GitSCMSource
:
import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever;
import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration;
import jenkins.plugins.git.GitSCMSource;
def globalLibsDesc = Jenkins.getInstance()
.getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
SCMSourceRetriever retriever = new SCMSourceRetriever(new GitSCMSource(
"someId",
"mygitrepo",
"credentialId",
"*",
"",
false))
LibraryConfiguration pipeline = new LibraryConfiguration("pipeline", retriever)
.setDefaultVersion(env.BRANCH_NAME)
.setImplicit(true)
globalLibsDesc.get().setLibraries([pipeline])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With