Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Example: run_groovy_script.sh ../wendy.ini add_global_pipeline_library.groovy <owner> <repo> [<branch> <ssh credentials id> <scan credentials id>]
- import jenkins.model.*
- import org.jenkinsci.plugins.workflow.libs.*
- import org.jenkinsci.plugins.github_branch_source.*
- import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy
- String owner = args[0]
- String repo = args[1]
- String branch = args.size() > 2 ? args[2] : 'master'
- String sshCredentialsId = args.size() > 3 ? args[3] : 'jenkinsgithub'
- String scanCredentialsId = args.size() > 4 ? args[4] : 'githubjenkins'
- def inst = Jenkins.getInstance()
- def desc = inst.getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
- GitHubSCMSource source = {
- GitHubSCMSource _source = new GitHubSCMSource(owner, repo)
- _source.setCredentialsId(scanCredentialsId)
- _source.traits.add(new BranchDiscoveryTrait(true, true));
- _source.traits.add(new OriginPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.HEAD)));
- _source.traits.add(new ForkPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.HEAD), new ForkPullRequestDiscoveryTrait.TrustContributors()));
- _source.traits.add(new SSHCheckoutTrait(sshCredentialsId));
- return _source
- }()
- SCMSourceRetriever retriever = new SCMSourceRetriever(source)
- LibraryConfiguration libconfig = new LibraryConfiguration(repo, retriever)
- libconfig.setDefaultVersion(branch)
- libconfig.setImplicit(false)
- desc.get().setLibraries([libconfig])
Add Comment
Please, Sign In to add comment