Created
May 22, 2018 13:27
-
-
Save AdamSaleh/25c2fcf0e506c1bd14326b1833df40ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment