Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Jenkins Global Pipeline Library via Groovy

How can a Jenkins Global Pipeline Library, which can be configured in the Jenkins master, be set up using Groovy code?

enter image description here

like image 674
StephenKing Avatar asked Dec 01 '22 12:12

StephenKing


1 Answers

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])
like image 200
Joan Avatar answered Dec 09 '22 14:12

Joan