49 lines
1.5 KiB
Groovy
49 lines
1.5 KiB
Groovy
def addGitlabGroupRepository(RepositoryHandler handler, String groupName, String groupId) {
|
|
handler.maven {
|
|
name = "Gitlab Group - $groupName"
|
|
url = "${gitlabCiApiUrl}/groups/${groupId}/-/packages/maven"
|
|
setGitlabRepoAuth(it)
|
|
}
|
|
}
|
|
|
|
def addGitlabPublishingRepository(RepositoryHandler handler) {
|
|
handler.maven {
|
|
name = "Gitlab_Project"
|
|
url = "${gitlabCiApiUrl}/projects/${gitlabCiProjectId}/packages/maven"
|
|
setGitlabRepoAuth(it)
|
|
}
|
|
}
|
|
|
|
def setGitlabRepoAuth(MavenArtifactRepository maven) {
|
|
if (System.getenv("CI_JOB_TOKEN") != null) {
|
|
maven.credentials(HttpHeaderCredentials) {
|
|
name = 'Job-Token'
|
|
value = System.getenv("CI_JOB_TOKEN")
|
|
}
|
|
} else if (project.hasProperty("gitlabPrivateToken")) {
|
|
maven.credentials(HttpHeaderCredentials) {
|
|
name = 'Private-Token'
|
|
value = gitlabPrivateToken
|
|
}
|
|
} else if (System.getenv("GITLAB_PRIVATE_TOKEN") != null) {
|
|
maven.credentials(HttpHeaderCredentials) {
|
|
name = 'Private-Token'
|
|
value = System.getenv("GITLAB_PRIVATE_TOKEN")
|
|
}
|
|
}
|
|
else {
|
|
throw Exception("No gitlab maven repository auth configured")
|
|
}
|
|
|
|
maven.authentication {
|
|
header(HttpHeaderAuthentication)
|
|
}
|
|
}
|
|
|
|
// Export methods by turning them into closures
|
|
ext {
|
|
setGitlabRepoAuth = this.&setGitlabRepoAuth
|
|
addGitlabPublishingRepository = this.&addGitlabPublishingRepository
|
|
addGitlabGroupRepository = this.&addGitlabGroupRepository
|
|
}
|