Guest User

Untitled

a guest
May 26th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #!groovy
  2.  
  3. // imports
  4. import hudson.scm.SCM
  5. import jenkins.model.Jenkins
  6. import jenkins.plugins.git.GitSCMSource
  7. import org.jenkinsci.plugins.workflow.libs.*
  8. import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration
  9. import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever
  10.  
  11. // parameters
  12. def globalLibrariesParameters = [
  13. branch: "master",
  14. credentialId: "global-shared-library-key",
  15. implicit: false,
  16. name: "Your Global Shared Library name here",
  17. repository: "git@bitbucket.org:your-company/your-repo.git"
  18. ]
  19.  
  20. // define global library
  21. GitSCMSource gitSCMSource = new GitSCMSource(
  22. "global-shared-library",
  23. globalLibrariesParameters.repository,
  24. globalLibrariesParameters.credentialId,
  25. "*",
  26. "",
  27. false
  28. )
  29.  
  30. // define retriever
  31. SCMSourceRetriever sCMSourceRetriever = new SCMSourceRetriever(gitSCMSource)
  32.  
  33. // get Jenkins instance
  34. Jenkins jenkins = Jenkins.getInstance()
  35.  
  36. // get Jenkins Global Libraries
  37. def globalLibraries = jenkins.getDescriptor("org.jenkinsci.plugins.workflow.libs.GlobalLibraries")
  38.  
  39. // define new library configuration
  40. LibraryConfiguration libraryConfiguration = new LibraryConfiguration(globalLibrariesParameters.name, sCMSourceRetriever)
  41. libraryConfiguration.setDefaultVersion(globalLibrariesParameters.branch)
  42. libraryConfiguration.setImplicit(globalLibrariesParameters.implicit)
  43.  
  44. // set new Jenkins Global Library
  45. globalLibraries.get().setLibraries([libraryConfiguration])
  46.  
  47. // save current Jenkins state to disk
  48. jenkins.save()
Add Comment
Please, Sign In to add comment