Last active
December 8, 2022 16:43
-
-
Save baymac/f1a2249a0ec7b999c057056937e752a6 to your computer and use it in GitHub Desktop.
A sample job dsl configuration of gitlab folder organisation
This file contains 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 (locationConfig != null && locationConfig.getUrl() != null) { | |
locationConfig.getUrl().contains("staging") | |
} else { | |
System.getenv("ENVIRONMENT") == "sandbox" | |
} | |
} | |
List<Map> gitlab = [] | |
if (isSandbox()) { | |
gitlab = [ | |
[name: 'tests', displayName: 'Jenkins Tests', group: 'jenkins/tests'], | |
] | |
} else { | |
gitlab = [ | |
[name: 'DevOps'], | |
[name: 'DentalDesktop'], | |
[name: 'Shared'], | |
[name: 'Ortho', folder: 'Ortho'], | |
[name: 'OrthoClinic', folder: 'Ortho'], | |
[name: 'InternalTools', displayName: 'Internal Tools'], | |
] | |
} | |
def folders = gitlab.collect { it.folder }.unique() - null | |
folders.each { | |
folder(it) { | |
} | |
} | |
gitlab.each { Map org -> | |
gitlabOrgs(org).call() | |
} | |
Closure gitlabOrgs(Map args = [:]) { | |
def config = [ | |
displayName: args.name, | |
group: args.name, | |
suppressDefaultJenkinsfile: false, | |
] << args | |
def name = config.folder ? "${config.folder}/${config.name}" : config.name | |
GString orgDescription = "<br>${config.displayName} group projects" | |
return { | |
organizationFolder(name) { | |
organizations { | |
displayName(config.displayName) | |
description(orgDescription) | |
gitLabSCMNavigator { | |
projectOwner(config.group) | |
credentialsId('gitlab_ssh_key') | |
serverName('git.3shape.local') | |
traits { | |
subGroupProjectDiscoveryTrait() // discover projects inside subgroups | |
gitLabBranchDiscovery { | |
strategyId(3) // discover all branches | |
} | |
originMergeRequestDiscoveryTrait { | |
strategyId(1) // discover MRs and merge them with target branch | |
} | |
gitLabTagDiscovery() // discover tags | |
gitLFSPullTrait() | |
} | |
} | |
} | |
// "Traits" ("Behaviours" in the GUI) that are NOT "declarative-compatible" | |
// For some 'traits, we need to configure this stuff by hand until JobDSL handles it | |
// https://issues.jenkins.io/browse/JENKINS-45504 | |
configure { | |
def traits = it / navigators / 'io.jenkins.plugins.gitlabbranchsource.GitLabSCMNavigator' / traits | |
traits << 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait' { | |
strategyId 2 | |
trust(class: 'io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait$TrustPermission') | |
} | |
} | |
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
Thank you for sharing