From 86ca5da40cf97204110e81e51fff232387b5ab44 Mon Sep 17 00:00:00 2001
From: Jan Zickermann <jan.zickermann@dataport.de>
Date: Mon, 4 Nov 2024 12:41:55 +0100
Subject: [PATCH] #1 Add gitlab pipeline

---
 .gitlab-ci.yml      | 47 ++++++++++++++++++++++++++++++++
 .m2/ci_settings.xml | 66 +++++++++++++++++++++++++++++++++++++++++++++
 pom.xml             | 40 +++++++++++++++++++++++++++
 3 files changed, 153 insertions(+)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 .m2/ci_settings.xml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..bf4ef22
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,47 @@
+image: maven:3.9.9-eclipse-temurin-23-alpine
+
+variables:
+  MAVEN_DEPLOY_CLI_OPTS: "--no-transfer-progress -DskipTests"
+  MAVEN_CLI_OPTS: >-
+    -s .m2/ci_settings.xml --batch-mode
+    -Dmaven.plugin.validation=brief
+
+services:
+  - docker:dind
+
+cache:
+  paths:
+    - .m2/repository/
+    - target/
+
+stages:
+  - build
+  - deploy
+
+verify:
+  stage: build
+  script:
+    - echo "mvn verify $MAVEN_CLI_OPTS"
+    - mvn help:effective-settings $MAVEN_CLI_OPTS
+    - mvn verify $MAVEN_CLI_OPTS
+  artifacts:
+    paths:
+      - target/*.jar
+
+deploy-gitlab:
+  stage: deploy
+  script:
+    - echo "mvn deploy -Pgitlab-deploy $MAVEN_DEPLOY_CLI_OPTS $MAVEN_CLI_OPTS"
+    - mvn deploy -Pgitlab-deploy $MAVEN_DEPLOY_CLI_OPTS $MAVEN_CLI_OPTS
+  only:
+    - main
+    - release
+
+deploy-nexus:
+  stage: deploy
+  script:
+    - echo "mvn deploy -Pnexus-deploy $MAVEN_DEPLOY_CLI_OPTS $MAVEN_CLI_OPTS"
+    - mvn deploy -Pnexus-deploy $MAVEN_DEPLOY_CLI_OPTS $MAVEN_CLI_OPTS
+  only:
+    - main
+    - release
diff --git a/.m2/ci_settings.xml b/.m2/ci_settings.xml
new file mode 100644
index 0000000..d6113a6
--- /dev/null
+++ b/.m2/ci_settings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"
+		  xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<localRepository>.m2/repository</localRepository>
+
+	<servers>
+		<server>
+			<id>ozg-nexus</id>
+			<username>${env.NEXUS_USER}</username>
+			<password>${env.NEXUS_PASSWORD}</password>
+		</server>
+		<server>
+			<id>ozg-snapshots-nexus</id>
+			<username>${env.NEXUS_USER}</username>
+			<password>${env.NEXUS_PASSWORD}</password>
+		</server>
+		<server>
+			<id>codesh-gitlab</id>
+			<username>${env.CI_REGISTRY_USER}</username>
+			<password>${env.CI_REGISTRY_PASSWORD}</password>
+		</server>
+		<server>
+			<id>codesh-gitlab-snapshots</id>
+			<username>${env.CI_REGISTRY_USER}</username>
+			<password>${env.CI_REGISTRY_PASSWORD}</password>
+		</server>
+	</servers>
+	<profiles>
+		<profile>
+			<id>gitlab-deploy</id>
+			<repositories>
+				<repository>
+					<id>codesh-gitlab</id>
+					<name>codesh-gitlab</name>
+					<url>${env.CI_REGISTRY}</url>
+				</repository>
+				<repository>
+					<id>codesh-gitlab-snapshots</id>
+					<name>codesh-gitlab-snapshots</name>
+					<url>${env.CI_REGISTRY}</url>
+					<snapshots>
+						<enabled>true</enabled>
+					</snapshots>
+				</repository>
+			</repositories>
+		</profile>
+		<profile>
+			<id>nexus-deploy</id>
+			<repositories>
+				<repository>
+					<id>ozg-nexus</id>
+					<name>ozg-releases</name>
+					<url>https://nexus.ozg-sh.de/repository/ozg-releases/</url>
+				</repository>
+				<repository>
+					<id>ozg-snapshots-nexus</id>
+					<name>ozg-snapshots</name>
+					<url>https://nexus.ozg-sh.de/repository/ozg-snapshots/</url>
+					<snapshots>
+						<enabled>true</enabled>
+					</snapshots>
+				</repository>
+			</repositories>
+		</profile>
+	</profiles>
+</settings>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index be5a5b4..c13d43e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -121,4 +121,44 @@
 			</plugin>
 		</plugins>
 	</build>
+
+	<profiles>
+		<!-- Deployment Profiles -->
+		<profile>
+			<id>gitlab-deploy</id>
+			<activation>
+				<activeByDefault>false</activeByDefault>
+			</activation>
+			<distributionManagement>
+				<repository>
+					<id>codesh-gitlab</id>
+					<name>codesh-gitlab</name>
+					<url>${env.CI_REGISTRY}</url>
+				</repository>
+				<snapshotRepository>
+					<id>codesh-gitlab-snapshots</id>
+					<name>codesh-gitlab-snapshots</name>
+					<url>${env.CI_REGISTRY}</url>
+				</snapshotRepository>
+			</distributionManagement>
+		</profile>
+		<profile>
+			<id>nexus-deploy</id>
+			<activation>
+				<activeByDefault>false</activeByDefault>
+			</activation>
+			<distributionManagement>
+				<repository>
+					<id>ozg-nexus</id>
+					<name>ozg-releases</name>
+					<url>https://nexus.ozg-sh.de/repository/ozg-releases/</url>
+				</repository>
+				<snapshotRepository>
+					<id>ozg-snapshots-nexus</id>
+					<name>ozg-snapshots</name>
+					<url>https://nexus.ozg-sh.de/repository/ozg-snapshots/</url>
+				</snapshotRepository>
+			</distributionManagement>
+		</profile>
+	</profiles>
 </project>
-- 
GitLab