From 54f7b1c2da0b5a794bcab44a77c78b6d4cdb093c Mon Sep 17 00:00:00 2001 From: ansgarz Date: Fri, 30 Jun 2023 13:56:31 +0200 Subject: [PATCH] publish also to gitlab --- .gitlab-ci.yml | 36 +++++++++++++++++++++++++++++------- build.gradle | 19 +++++++++++++++---- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 43b486a..aef9780 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,20 +21,18 @@ cache: - .gradle/wrapper - .gradle/caches + build: stage: build script: - echo "---------- build stage ----------" - - apt-get update -y - - apt-get install -y iputils-ping ssh - - ping -c 2 repo.prod.meissa.de - - ssh-keyscan repo.prod.meissa.de - ./gradlew assemble artifacts: paths: - build/libs/*.jar expire_in: 1 week + test: stage: test image: docker:latest @@ -61,20 +59,44 @@ test: junit: build/test-results/test/TEST-*.xml -publish-maven-package: - stage: publish +package: + stage: package rules: - if: $CI_PIPELINE_SOURCE != "push" when: never - if: $CI_COMMIT_TAG !~ /^release-[0-9]+[.][0-9]+([.][0-9]+)?$/ script: - ./gradlew -x assemble -x test jar - - ./gradlew -x assemble -x test publish artifacts: paths: - build/libs/*.jar +publish-maven-package-to-gitlab: + stage: publish + rules: + - if: $CI_PIPELINE_SOURCE != "push" + when: never + - if: $CI_COMMIT_TAG !~ /^release-[0-9]+[.][0-9]+([.][0-9]+)?$/ + script: + - ./gradlew -x assemble -x test publishLibraryPublicationToGitlabRepository + + +publish-maven-package-to-meissa: + stage: publish + allow_failure: true + rules: + - if: $CI_PIPELINE_SOURCE != "push" + when: never + - if: $CI_COMMIT_TAG !~ /^release-[0-9]+[.][0-9]+([.][0-9]+)?$/ + script: + - apt-get update -y + - apt-get install -y iputils-ping ssh + - ping -c 2 repo.prod.meissa.de + - ssh-keyscan repo.prod.meissa.de + - ./gradlew -x assemble -x test publishLibraryPublicationToMeissaRepository + + release: stage: release rules: diff --git a/build.gradle b/build.gradle index fef3097..6bf0c27 100644 --- a/build.gradle +++ b/build.gradle @@ -182,6 +182,17 @@ publishing { } repositories { + maven { + name = "gitlab" + url = "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/packages/maven" + credentials(HttpHeaderCredentials) { + name = "Job-Token" + value = System.getenv("CI_JOB_TOKEN") + } + authentication { + header(HttpHeaderAuthentication) + } + } maven { name = "meissa" url = uri("https://repo.prod.meissa.de/api/packages/meissa/maven") @@ -189,12 +200,12 @@ publishing { credentials(HttpHeaderCredentials) { name = "Authorization" if (System.getenv("CI_JOB_TOKEN") != null) { - def tok = System.getenv("RELEASE_TOKEN") - if (tok == null) { + def tokenFromEnv = System.getenv("RELEASE_TOKEN") + if (tokenFromEnv == null) { println "Error: RELEASE_TOKEN not found" } else { - value = "token " + tok - println "RELEASE_TOKEN found - " + (10 < tok.length()) + value = "token " + tokenFromEnv + println "RELEASE_TOKEN found - " } } else { // use project-property (define e.g. in "~/.gradle/gradle.properties") when not running in ci