Created
March 17, 2020 11:13
-
-
Save zionyx/8daf22ccf509cfc5ab447dd504eaf6bb to your computer and use it in GitHub Desktop.
GitHub JobDSL @Casz
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
private boolean isSandbox() { | |
def locationConfig = jenkins.model.JenkinsLocationConfiguration.get() | |
if (System.getenv("ENVIRONMENT") == "sandbox") { | |
true | |
} else if (locationConfig != null && locationConfig.getUrl() != null) { | |
locationConfig.getUrl().contains("staging") | |
} else { | |
false | |
} | |
} | |
List<Map> github = [] | |
if (isSandbox()) { | |
github = [ | |
[name: 'tests', group: 'jenkins/tests'], | |
] | |
} else { | |
github = [ | |
[name: '3shape'], | |
] | |
} | |
def folders = github.collect { it.folder }.unique() - null | |
folders.each { | |
folder(it) { | |
} | |
} | |
github.each { Map org -> | |
githubOrgs(org).call() | |
if (org.nightly) { | |
githubOrgs(org).call() | |
} | |
} | |
Closure githubOrgs(Map args = [:]) { | |
def config = [ | |
group: args.name, | |
includes: ['*'], | |
excludes: [], | |
suppressDefaultJenkinsfile: false, | |
] << args | |
def folderName = config.folder ? "${config.folder}/${config.name}" : config.name | |
GString orgDescription = "<br>${config.displayName} group projects" | |
config.includes = config.includes.join(' ') | |
config.excludes = config.excludes.join(' ') | |
return { | |
organizationFolder(folderName) { | |
organizations { | |
github { | |
repoOwner(config.name) | |
apiUri('https://api.github.com') | |
credentialsId('github_user_token') | |
traits { | |
gitHubBranchDiscovery { | |
strategyId(1) // Exclude branches that are also filed as PRs | |
} | |
gitLFSPullTrait() | |
sourceWildcardFilter { | |
includes(config.includes) | |
excludes(config.excludes) | |
} | |
cloneOptionTrait { | |
extension { | |
noTags(false) | |
shallow(false) | |
reference('') | |
timeout(10) | |
honorRefspec(false) | |
} | |
} | |
} | |
} | |
} | |
buildStrategies { | |
buildChangeRequests { | |
ignoreTargetOnlyChanges(true) | |
ignoreUntrustedChanges(false) | |
} | |
skipInitialBuildOnFirstBranchIndexing() | |
buildTags { | |
atLeastDays '-1' | |
atMostDays '7' | |
} | |
} | |
configure { | |
def traits = it / navigators / 'org.jenkinsci.plugins.github__branch__source.GitHubSCMNavigator' / traits | |
traits << 'org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait' { | |
strategyId(1) | |
trust(class: 'org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait$TrustPermission') | |
} | |
traits << 'org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait' { | |
strategyId(1) | |
} | |
} | |
orphanedItemStrategy { | |
discardOldItems { | |
daysToKeep(7) | |
numToKeep(10) | |
} | |
} | |
if (!isSandbox()) { | |
triggers { | |
periodicFolderTrigger { | |
interval('1d') | |
} | |
} | |
} | |
projectFactories { | |
workflowMultiBranchProjectFactory { | |
scriptPath('Jenkinsfile') | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @zionyx do you any documnentation about the functions you used for this organizationFolder? I'm trying to find something, but no luck yet. I found the source code, but would like some docs on what's available and the options to configure my folder.
Thanks!