Guest User

Untitled

a guest
May 26th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. //Example: run_groovy_script.sh ../wendy.ini add_global_pipeline_library.groovy <owner> <repo> [<branch> <ssh credentials id> <scan credentials id>]
  2. import jenkins.model.*
  3. import org.jenkinsci.plugins.workflow.libs.*
  4. import org.jenkinsci.plugins.github_branch_source.*
  5. import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy
  6.  
  7. String owner = args[0]
  8. String repo = args[1]
  9. String branch = args.size() > 2 ? args[2] : 'master'
  10. String sshCredentialsId = args.size() > 3 ? args[3] : 'jenkinsgithub'
  11. String scanCredentialsId = args.size() > 4 ? args[4] : 'githubjenkins'
  12.  
  13. def inst = Jenkins.getInstance()
  14. def desc = inst.getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
  15.  
  16. GitHubSCMSource source = {
  17. GitHubSCMSource _source = new GitHubSCMSource(owner, repo)
  18. _source.setCredentialsId(scanCredentialsId)
  19. _source.traits.add(new BranchDiscoveryTrait(true, true));
  20. _source.traits.add(new OriginPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.HEAD)));
  21. _source.traits.add(new ForkPullRequestDiscoveryTrait(EnumSet.of(ChangeRequestCheckoutStrategy.HEAD), new ForkPullRequestDiscoveryTrait.TrustContributors()));
  22. _source.traits.add(new SSHCheckoutTrait(sshCredentialsId));
  23. return _source
  24. }()
  25.  
  26. SCMSourceRetriever retriever = new SCMSourceRetriever(source)
  27.  
  28. LibraryConfiguration libconfig = new LibraryConfiguration(repo, retriever)
  29. libconfig.setDefaultVersion(branch)
  30. libconfig.setImplicit(false)
  31. desc.get().setLibraries([libconfig])
Add Comment
Please, Sign In to add comment