From 990345e3b9821d788df5e523d94405c9bdba0bb0 Mon Sep 17 00:00:00 2001 From: Yongshun Shreck Ye Date: Sat, 23 Nov 2024 11:33:22 +0800 Subject: [PATCH] Initially adapt `gitlabMavenRepository` to make it work in GitLab CI/CD The adapted code is not tested yet. --- .../com/huanshankeji/GitlabPackageRegistryMaven.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/GitlabPackageRegistryMaven.kt b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/GitlabPackageRegistryMaven.kt index 857d477..a13158e 100644 --- a/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/GitlabPackageRegistryMaven.kt +++ b/kotlin-common-gradle-plugins/src/main/kotlin/com/huanshankeji/GitlabPackageRegistryMaven.kt @@ -19,8 +19,18 @@ fun Project.gitlabMavenRepository(repositoryHandler: RepositoryHandler, nameArg: url = uri(urlArg) name = nameArg credentials(HttpHeaderCredentials::class) { - name = "Private-Token" - value = findProperty("gitLabPrivateToken") as String? + val gitLabPrivateToken: String? by properties + val ciJobToken: String? = System.getenv("CI_JOB_TOKEN") + if (gitLabPrivateToken !== null) { + name = "Private-Token" + value = gitLabPrivateToken + + if (ciJobToken !== null) + logger.warn("Both the private token and the CI Job token are specified for the GitLab Maven package registry ${this@maven} and the private token takes precedence.") + } else if (ciJobToken !== null) { + name = "Job-Token" + value = ciJobToken + } } authentication { create("header", HttpHeaderAuthentication::class)