├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ ├── cd.yaml │ └── jenkins-security-scan.yml ├── .gitignore ├── .mvn ├── extensions.xml └── maven.config ├── Jenkinsfile ├── README.adoc ├── pom.xml └── src └── main ├── java └── org │ └── jenkinsci │ └── plugins │ └── pipeline │ └── github │ └── library │ └── GitHubLibraryResolver.java └── resources └── index.jelly /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @jenkinsci/pipeline-github-lib-plugin-developers 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: maven 4 | directory: / 5 | schedule: 6 | interval: monthly 7 | - package-ecosystem: github-actions 8 | directory: / 9 | schedule: 10 | interval: monthly 11 | -------------------------------------------------------------------------------- /.github/workflows/cd.yaml: -------------------------------------------------------------------------------- 1 | # Note: additional setup is required, see https://www.jenkins.io/redirect/continuous-delivery-of-plugins 2 | 3 | name: cd 4 | on: 5 | workflow_dispatch: 6 | check_run: 7 | types: 8 | - completed 9 | 10 | jobs: 11 | maven-cd: 12 | uses: jenkins-infra/github-reusable-workflows/.github/workflows/maven-cd.yml@v1 13 | secrets: 14 | MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} 15 | MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }} 16 | -------------------------------------------------------------------------------- /.github/workflows/jenkins-security-scan.yml: -------------------------------------------------------------------------------- 1 | name: Jenkins Security Scan 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | types: [ opened, synchronize, reopened ] 9 | workflow_dispatch: 10 | 11 | permissions: 12 | security-events: write 13 | contents: read 14 | actions: read 15 | 16 | jobs: 17 | security-scan: 18 | uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2 19 | with: 20 | java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate. 21 | # java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven build files 2 | target/ 3 | 4 | # Jenkins plugin development 5 | work/ 6 | 7 | # IntelliJ project files 8 | *.iml 9 | *.ipr 10 | *.iws 11 | .idea/ 12 | 13 | # Eclipse project files 14 | .settings/ 15 | .classpath 16 | .project 17 | .metadata 18 | .loadpath 19 | 20 | # NetBeans project files 21 | nbproject/private/ 22 | build/ 23 | nbbuild/ 24 | dist/ 25 | nbdist/ 26 | nbactions.xml 27 | nb-configuration.xml 28 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | io.jenkins.tools.incrementals 4 | git-changelist-maven-extension 5 | 1.8 6 | 7 | 8 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Pconsume-incrementals 2 | -Pmight-produce-incrementals 3 | -Dchangelist.format=%d.v%s 4 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | /* 2 | See the documentation for more options: 3 | https://github.com/jenkins-infra/pipeline-library/ 4 | */ 5 | buildPlugin( 6 | useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests 7 | configurations: [ 8 | [platform: 'linux', jdk: 21], 9 | [platform: 'windows', jdk: 17], 10 | ]) 11 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | == Pipeline: GitHub Groovy Libraries 2 | 3 | Allows Pipeline Groovy libraries to be loaded on the fly from public repositories on GitHub. 4 | Unlike regular library definitions, no preconfiguration at the global or folder level is needed. 5 | 6 | Example: 7 | 8 | [source,groovy] 9 | ---- 10 | @Library('github.com/jglick/sample-pipeline-library') _ 11 | if (currentBuildExt().hasChangeIn('src')) { 12 | return 13 | } 14 | node { 15 | sh 'make' 16 | } 17 | ---- 18 | 19 | link:https://www.jenkins.io/doc/book/pipeline/shared-libraries/#automatic-shared-libraries[Documentation] 20 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | 4.0.0 28 | 29 | 30 | org.jenkins-ci.plugins 31 | plugin 32 | 5.9 33 | 34 | 35 | 36 | org.jenkins-ci.plugins 37 | pipeline-github-lib 38 | ${changelist} 39 | hpi 40 | 41 | Pipeline: GitHub Groovy Libraries 42 | https://github.com/jenkinsci/${project.artifactId}-plugin 43 | 44 | 45 | MIT License 46 | https://opensource.org/licenses/MIT 47 | 48 | 49 | 50 | 51 | scm:git:https://github.com/${gitHubRepo} 52 | scm:git:https://github.com/${gitHubRepo} 53 | ${scmTag} 54 | https://github.com/${gitHubRepo} 55 | 56 | 57 | 58 | 999999-SNAPSHOT 59 | jenkinsci/${project.artifactId}-plugin 60 | 61 | 2.479 62 | ${jenkins.baseline}.1 63 | 64 | 65 | 66 | 67 | repo.jenkins-ci.org 68 | https://repo.jenkins-ci.org/public/ 69 | 70 | 71 | 72 | 73 | repo.jenkins-ci.org 74 | https://repo.jenkins-ci.org/public/ 75 | 76 | 77 | 78 | 79 | 80 | 81 | io.jenkins.tools.bom 82 | bom-${jenkins.baseline}.x 83 | 3893.v213a_42768d35 84 | import 85 | pom 86 | 87 | 88 | 89 | 90 | 91 | 92 | org.jenkins-ci.plugins 93 | git 94 | 95 | 96 | io.jenkins.plugins 97 | pipeline-groovy-lib 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/pipeline/github/library/GitHubLibraryResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2016 CloudBees, Inc. 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | package org.jenkinsci.plugins.pipeline.github.library; 26 | 27 | import hudson.Extension; 28 | import hudson.model.Job; 29 | import java.util.ArrayList; 30 | import java.util.Arrays; 31 | import java.util.Collection; 32 | import java.util.List; 33 | import java.util.Map; 34 | import jenkins.plugins.git.GitSCMSource; 35 | import jenkins.plugins.git.traits.IgnoreOnPushNotificationTrait; 36 | import org.jenkinsci.plugins.workflow.libs.LibraryConfiguration; 37 | import org.jenkinsci.plugins.workflow.libs.LibraryResolver; 38 | import org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever; 39 | 40 | /** 41 | * Allows libraries to be loaded on the fly from GitHub. 42 | */ 43 | @Extension public class GitHubLibraryResolver extends LibraryResolver { 44 | 45 | @Override public boolean isTrusted() { 46 | return false; 47 | } 48 | 49 | @Override public Collection forJob(Job job, Map libraryVersions) { 50 | List libs = new ArrayList<>(); 51 | for (Map.Entry entry : libraryVersions.entrySet()) { 52 | if (entry.getKey().matches("github[.]com/([^/]+)/([^/]+)")) { 53 | String name = entry.getKey(); 54 | // Currently, GitHubSCMSource offers no particular advantage here over GitSCMSource. 55 | GitSCMSource scm = new GitSCMSource("https://" + name + ".git"); 56 | scm.setTraits(Arrays.asList( 57 | new IgnoreOnPushNotificationTrait() 58 | )); 59 | LibraryConfiguration lib = new LibraryConfiguration(name, new SCMSourceRetriever(scm)); 60 | lib.setDefaultVersion("master"); 61 | libs.add(lib); 62 | } 63 | } 64 | return libs; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 |
28 | Allows Pipeline Groovy libraries to be loaded on the fly from GitHub. 29 |
30 | --------------------------------------------------------------------------------