Skip to content
Snippets Groups Projects
Commit 56848fd3 authored by Lukas Malte Monnerjahn's avatar Lukas Malte Monnerjahn
Browse files

Merge branch 'KOP-3210-maven-settings-file' into 'main'

KOP-3210 maven settings file

See merge request !1
parents 058a8663 6ee851f7
No related branches found
No related tags found
1 merge request!1KOP-3210 maven settings file
<?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-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
<profiles>
<profile>
<id>ci-default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>codesh-gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</repository>
<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>
......@@ -2,11 +2,21 @@
This component provides jobs for building, testing, and deploying Maven projects.
In the first stage a download job can download the shared Maven settings file from '.m2/maven_ci_settings.xml' in this repository.
The settings file configures servers and repositories for GitLab and Nexus.
In the repositories 'CI/CD settings' in the 'Job token permissions' the project 'ozg-cloud/devops/ci-components'
has to be added to the allowlist for the download to work.
In order to publish OCI images in the deploy stage, the `spring-boot-maven-plugin` must be configured in the `pom.xml` file.
Also, you need to add a property `spring-boot.build-image.imageTags` to the `pom.xml` file and
set `image.tags` in the `spring-boot-maven-plugin` configuration to this property.
## Jobs
- Download the shared Maven settings (can be disabled)
- Build the project (`mvn clean compile`)
- Run tests (`mvn test`)
- Verify the project (`mvn verify`)
- Run integration tests (`mvn verify`)
- Deploy snapshots for Merge Requests
- Deploy snapshots for the main branch
- Deploy releases for git tags
......@@ -14,13 +24,16 @@ This component provides jobs for building, testing, and deploying Maven projects
## Inputs
| Parameter | Description | Default Value |
|----------------------------------|------------------------------------------------------------|---------------|
|----------------------------|---------------------------------------------------------------------|-----------------------------------------------------------------------|
| `job_prefix` | The prefix for the job names. | `maven` |
| `download_stage` | The stage in which the download job will run. | `download` |
| `download_settings` | Whether to download the Maven settings file. (boolean) | `true` |
| `build_stage` | The stage in which the build job will run. | `build` |
| `test_stage` | The stage in which the test and verify jobs will run. | `test` |
| `deploy_stage` | The stage in which the deploy jobs will run. | `publish` |
| `deployToGitlab` | Whether to deploy to GitLab. | `true` |
| `deployToNexus` | Whether to deploy to Nexus. | `true` |
| `deploy_to_gitlab` | Whether to deploy to GitLab. (boolean) | `true` |
| `deploy_to_nexus` | Whether to deploy to Nexus. (boolean) | `true` |
| `deploy_image` | Whether to deploy an image with spring-boot-maven plugin. (boolean) | `true` |
| `maven_cli_options` | Maven options to pass to the Maven commands. | `-s .m2/ci_settings.xml --batch-mode -Dmaven.plugin.validation=brief` |
| `maven_cli_deploy_options` | Additional Maven CLI options when publishing artifacts. | `--no-transfer-progress -DskipTests` |
| `nexus_image_registry` | URL of the Nexus image registry. | `docker.ozg-sh.de` |
......@@ -42,11 +55,14 @@ include:
- component: $CI_SERVER_FQDN/ozg-cloud/devops/ci-components/maven@<version>
inputs:
job_prefix: "custom"
download_stage: "download"
download_settings: true
build_stage: "build"
test_stage: "test"
deploy_stage: "deploy"
deployToGitlab: false
deployToNexus: true
deploy_to_gitlab: false
deploy_to_nexus: true
deploy_image: true
maven_cli_options: >-
-s .m2/ci_settings.xml --batch-mode
-Dmaven.plugin.validation=brief
......
spec:
inputs:
job_prefix:
description: "Define a prefix for the job name"
description: "Define a prefix for the job names"
default: "maven"
download_stage:
description: "Stage for the download job"
default: download
download_settings:
description: "Whether to download the Maven settings file (boolean)"
default: true
build_stage:
description: "Stage for the build job"
default: build
......@@ -12,12 +18,15 @@ spec:
deploy_stage:
description: "Stage for the deploy jobs"
default: publish
deployToGitlab:
deploy_to_gitlab:
description: "Whether to deploy to GitLab (boolean)"
default: true
deployToNexus:
deploy_to_nexus:
description: "Whether to deploy to Nexus (boolean)"
default: true
deploy_image:
description: "Whether to deploy an image. If 'true' additional config for the spring-boot-maven-plugin will be set."
default: true
maven_cli_options:
description: "Maven CLI options"
default: >-
......@@ -29,9 +38,6 @@ spec:
nexus_image_registry:
description: "URL of the Nexus image registry"
default: "docker.ozg-sh.de"
main_branch:
description: "Main branch name. Snapshots are deployed from this branch."
default: "main"
---
.maven_job:
image: maven:3.9.9-eclipse-temurin-21-alpine
......@@ -40,142 +46,46 @@ spec:
- .m2/repository/
- target/
### Deploy Helpers
.maven_get_version:
before_script:
- PROJECT_VERSION="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout $[[ inputs.maven_cli_options ]])"
- export TRUNCATED_PROJECT_VERSION="$(echo "$PROJECT_VERSION" | cut -d '-' -f 1)"
- export PROJECT_ARTIFACT_ID="$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout $[[ inputs.maven_cli_options ]])"
.maven_get_merge_request_tags:
before_script:
- MERGE_REQUEST_TAG="${TRUNCATED_PROJECT_VERSION}-MR-${CI_MERGE_REQUEST_IID}"
- MERGE_REQUEST_IMAGE_TAG="${REGISTRY}:${MERGE_REQUEST_TAG}"
- export ARTIFACT_VERSION="${MERGE_REQUEST_TAG}-SNAPSHOT"
- export PRIMARY_IMAGE_TAG="${MERGE_REQUEST_TAG}"
- export IMAGE_TAGS="${MERGE_REQUEST_IMAGE_TAG},${MERGE_REQUEST_IMAGE_TAG}-${CI_COMMIT_SHORT_SHA}"
.maven_get_snapshot_tags:
before_script:
- SNAPSHOT_TAG="${TRUNCATED_PROJECT_VERSION}-${CI_COMMIT_BRANCH}"
- SNAPSHOT_IMAGE_TAG="${REGISTRY}:${SNAPSHOT_TAG}"
- export ARTIFACT_VERSION="${TRUNCATED_PROJECT_VERSION}-SNAPSHOT"
- export PRIMARY_IMAGE_TAG=${SNAPSHOT_TAG}
- export IMAGE_TAGS="${SNAPSHOT_IMAGE_TAG},${SNAPSHOT_IMAGE_TAG}-${CI_COMMIT_SHORT_SHA},${REGISTRY}:snapshot-latest"
.maven_get_release_tags:
before_script:
- export ARTIFACT_VERSION="${CI_COMMIT_TAG}"
- export PRIMARY_IMAGE_TAG=${CI_COMMIT_TAG}
- export IMAGE_TAGS="${REGISTRY}:${CI_COMMIT_TAG},${REGISTRY}:latest"
.maven_deploy_to_gitlab:
before_script:
- !reference [ .maven_get_version, before_script ]
- export REGISTRY="$CI_REGISTRY_IMAGE"
- export MAVEN_PROFILE="-Pgitlab-deploy"
.maven_deploy_to_nexus:
before_script:
- !reference [ .maven_get_version, before_script ]
- export REGISTRY="$[[ inputs.nexus_image_registry ]]/${PROJECT_ARTIFACT_ID}"
- export MAVEN_PROFILE="-Pnexus-deploy"
.maven_deploy_template:
stage: $[[ inputs.deploy_stage ]]
script:
- mvn versions:set -DnewVersion=$ARTIFACT_VERSION $[[ inputs.maven_cli_options ]]
- mvn deploy ${MAVEN_PROFILE} $[[ inputs.maven_cli_options ]] $[[ inputs.maven_cli_deploy_options ]]
### Build Stage
"$[[ inputs.job_prefix ]]_build":
stage: $[[ inputs.build_stage ]]
extends:
- .maven_job
script:
- mvn clean compile $[[ inputs.maven_cli_options ]] --update-snapshots
### Test Stage
"$[[ inputs.job_prefix ]]_test":
stage: $[[ inputs.test_stage ]]
extends:
- .maven_job
script:
- mvn test $[[ inputs.maven_cli_options ]]
"$[[ inputs.job_prefix ]]_verify":
stage: $[[ inputs.test_stage ]]
extends:
- .maven_job
$[[ inputs.job_prefix ]]_download_settings:
stage: $[[ inputs.download_stage ]]
image: maven:3.9.9-eclipse-temurin-21-alpine
variables:
CI_COMPONENTS_PROJECT_ID: 241
script:
- mvn verify $[[ inputs.maven_cli_options ]]
### Deploy Stage
"$[[ inputs.job_prefix ]]_push_merge_request_snapshot_gitlab":
extends:
- .maven_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_gitlab, before_script ]
- !reference [ .maven_get_merge_request_tags, before_script ]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && '$[[ inputs.deployToGitlab ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_merge_request_snapshot_nexus":
stage: $[[ inputs.deploy_stage ]]
extends:
- .maven_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_nexus, before_script ]
- !reference [ .maven_get_merge_request_tags, before_script ]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && '$[[ inputs.deployToNexus ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_main_branch_snapshot_gitlab":
stage: $[[ inputs.deploy_stage ]]
extends:
- .maven_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_gitlab, before_script ]
- !reference [ .maven_get_snapshot_tags, before_script ]
rules:
- if: $CI_COMMIT_BRANCH == '$[[ inputs.main_branch ]]' && '$[[ inputs.deployToGitlab ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_main_branch_snapshot_nexus":
stage: $[[ inputs.deploy_stage ]]
extends:
- .maven_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_nexus, before_script ]
- !reference [ .maven_get_snapshot_tags, before_script ]
rules:
- if: $CI_COMMIT_BRANCH == '$[[ inputs.main_branch ]]' && '$[[ inputs.deployToNexus ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_release_gitlab":
stage: $[[ inputs.deploy_stage ]]
extends:
- .maven_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_gitlab, before_script ]
- !reference [ .maven_get_release_tags, before_script ]
- mkdir .m2
- >-
curl -f --header "PRIVATE-TOKEN: $CI_JOB_TOKEN"
"${CI_API_V4_URL}/projects/${CI_COMPONENTS_PROJECT_ID}/repository/files/.m2%2Fmaven_ci_settings.xml/raw?ref=KOP-3210-maven-settings-file"
--output .m2/ci_settings.xml
artifacts:
paths:
- .m2/ci_settings.xml
rules:
- if: $CI_COMMIT_TAG && '$[[ inputs.deployToGitlab ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_release_nexus":
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && '$[[ inputs.download_settings ]]' == 'true'
- if: $CI_PIPELINE_SOURCE == 'push' && '$[[ inputs.download_settings ]]' == 'true'
- if: $CI_COMMIT_TAG && '$[[ inputs.download_settings ]]' == 'true'
###
include:
# Build, Test and Verify
- component: $CI_SERVER_FQDN/ozg-cloud/devops/ci-components/maven_build@main
inputs:
job_prefix: $[[ inputs.job_prefix ]]
build_stage: $[[ inputs.build_stage ]]
test_stage: $[[ inputs.test_stage ]]
maven_cli_options: $[[ inputs.maven_cli_options ]]
# Get artifact name, version and image tags
- component: $CI_SERVER_FQDN/ozg-cloud/devops/ci-components/maven_get_version@main
inputs:
maven_cli_options: $[[ inputs.maven_cli_options ]]
# Publish
- component: $CI_SERVER_FQDN/ozg-cloud/devops/ci-components/maven_deploy@main
inputs:
job_prefix: $[[ inputs.job_prefix ]]
stage: $[[ inputs.deploy_stage ]]
extends:
- .maven_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_nexus, before_script ]
- !reference [ .maven_get_release_tags, before_script ]
rules:
- if: $CI_COMMIT_TAG && '$[[ inputs.deployToNexus ]]' == 'true'
deploy_to_gitlab: $[[ inputs.deploy_to_gitlab ]]
deploy_to_nexus: $[[ inputs.deploy_to_nexus ]]
deploy_image: $[[ inputs.deploy_image ]]
maven_cli_options: $[[ inputs.maven_cli_options ]]
maven_cli_deploy_options: $[[ inputs.maven_cli_deploy_options ]]
nexus_image_registry: $[[ inputs.nexus_image_registry ]]
......@@ -10,7 +10,7 @@ spec:
maven_cli_options:
description: "Maven CLI options"
---
.maven_build:
.maven_build_job:
image: maven:3.9.9-eclipse-temurin-21-alpine
cache:
paths:
......@@ -20,20 +20,20 @@ spec:
"$[[ inputs.job_prefix ]]_build":
stage: $[[ inputs.build_stage ]]
extends:
- .maven_build
- .maven_build_job
script:
- mvn clean compile $[[ inputs.maven_cli_options ]] --update-snapshots
"$[[ inputs.job_prefix ]]_test":
stage: $[[ inputs.test_stage ]]
extends:
- .maven_build
- .maven_build_job
script:
- mvn test $[[ inputs.maven_cli_options ]]
"$[[ inputs.job_prefix ]]_verify":
stage: $[[ inputs.test_stage ]]
extends:
- .maven_build
- .maven_build_job
script:
- mvn verify $[[ inputs.maven_cli_options ]]
\ No newline at end of file
# Maven Deploy Component
Runs `mvn deploy` to publish JAR archives or OCI images. Deprecated by `maven` component, that includes this functionality.
Runs `mvn deploy` to publish JAR archives or OCI images.
Requires the `maven_get_version` component to be included in the pipeline.
In order to publish OCI images, the `spring-boot-maven-plugin` must be configured in the `pom.xml` file.
Also, you need to add a property `spring-boot.build-image.imageTags` to the `pom.xml` file and
set `image.tags` in the `spring-boot-maven-plugin` configuration to this property.
## Jobs
- Manual Job for publishing snapshots for Merge Requests
- hidden helper jobs that do not run (prefix: `maven_deploy_`)
- Publish snapshots for Merge Requests
- Publish snapshots for the main branch
- Publish releases for git tags
## Inputs
| Parameter | Description | Default Value |
|----------------------------------|----------------------------------------------------------------|---------------|
|----------------------------------|-------------------------------------------------------------------------------------------------------|--------------------------------------|
| `job_prefix` | The prefix for the job names. | `maven` |
| `stage` | The stage in which the jobs will run. | `publish` |
| `deploy_to_gitlab` | Whether to deploy to GitLab or not. | `true` |
| `deploy_to_nexus` | Whether to deploy to Nexus or not. | `true` |
| `deploy_image` | Whether to deploy an image. If 'true' additional config for the spring-boot-maven-plugin will be set. | `true` |
| `maven_cli_options` | Maven options to pass to the maven commands. | |
| `maven_profile` | Maven Profile to use when publishing artifacts or images. | "" |
| `image_registry` | URL of the image registry. Only needed for container projects. | "" |
| `append_artifact_id_to_registry` | Whether to append the artifact ID to the Registry URL | `false` |
| `main_branch` | Branch for which to always publish snapshots. | `main` |
| `maven_cli_deploy_options` | Additional Maven CLI options when publishing artifacts. | `--no-transfer-progress -DskipTests` |
| `nexus_image_registry` | URL of the nexus image registry. Only needed for container projects pushing to nexus. | `docker.ozg-sh.de` |
## Usage Example
```yaml
......@@ -27,19 +34,20 @@ include:
maven_cli_options: >-
-s .m2/ci_settings.xml --batch-mode
-Dmaven.plugin.validation=brief
maven_profile: "-Pgitlab-deploy"
```
```yaml
include:
- component: $CI_SERVER_FQDN/ozg-cloud/devops/ci-components/maven_deploy@<version>
inputs:
job_prefix: "nexus"
job_prefix: "maven"
stage: "publish"
maven_cli_options: >-
-s .m2/ci_settings.xml --batch-mode
-Dmaven.plugin.validation=brief
maven_profile: "-Pnexus-deploy"
image_registry: "docker.ozg-sh.de"
deploy_to_gitlab: "true"
deploy_to_nexus: "true"
deploy_image: "true"
nexus_image_registry: "docker.ozg-sh.de"
append_artifact_id_to_registry: "true"
```
\ No newline at end of file
......@@ -5,92 +5,157 @@ spec:
default: "maven"
stage:
default: publish
deploy_to_gitlab:
description: "Whether to deploy to GitLab (boolean)"
default: true
deploy_to_nexus:
description: "Whether to deploy to Nexus (boolean)"
default: true
deploy_image:
description: "Whether to deploy an image. If 'true' additional config for the spring-boot-maven-plugin will be set."
default: true
maven_cli_options:
description: "Maven CLI options"
maven_profile:
description: "Maven profile to activate"
default: ""
image_registry:
description: "URL of the image registry"
default: ""
append_artifact_id_to_registry:
description: "Whether to append the artifact ID to the Registry URL (boolean)"
default: false
main_branch:
default: "main"
default: >-
-s .m2/ci_settings.xml --batch-mode
-Dmaven.plugin.validation=brief
maven_cli_deploy_options:
description: "Additional Maven CLI options when publishing artifacts"
default: "--no-transfer-progress -DskipTests"
nexus_image_registry:
description: "URL of the Nexus image registry"
default: "docker.ozg-sh.de"
---
### Deploy Helpers
.maven_deploy:
.maven_deploy_job:
image: maven:3.9.9-eclipse-temurin-21-alpine
cache:
paths:
- .m2/repository/
- target/
variables:
MAVEN_DEPLOY_CLI_OPTIONS: "--no-transfer-progress -DskipTests"
".maven_deploy_get_version":
.maven_deploy_to_gitlab:
before_script:
- PROJECT_VERSION="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout $[[ inputs.maven_cli_options ]])"
- export TRUNCATED_PROJECT_VERSION="$(echo "$PROJECT_VERSION" | cut -d '-' -f 1)"
- export PROJECT_ARTIFACT_ID="$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout $[[ inputs.maven_cli_options ]])"
- !reference [ .maven_get_version, before_script ]
- export REGISTRY="$CI_REGISTRY_IMAGE"
- export MAVEN_DEPLOY_PROFILE="-DaltSnapshotDeploymentRepository=codesh-gitlab-maven::default::${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven
-DaltReleaseDeploymentRepository=codesh-gitlab-maven::default::${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven"
".maven_deploy_get_image_tags":
.maven_deploy_image_to_gitlab:
before_script:
- if [ $[[ inputs.append_artifact_id_to_registry ]] = true ]; then
- REGISTRY="$[[ inputs.image_registry ]]/${PROJECT_ARTIFACT_ID}"
- else
- REGISTRY="$[[ inputs.image_registry ]]"
- export MAVEN_DEPLOY_PROFILE="${MAVEN_DEPLOY_PROFILE}
-Ddocker.publishRegistry.username=${CI_REGISTRY_USER}
-Ddocker.publishRegistry.password=${CI_REGISTRY_PASSWORD}
-Ddocker.publishRegistry.url=${CI_REGISTRY}
-Dspring-boot.build-image.publish=true
-Dspring-boot.build-image.imageName=${CI_REGISTRY_IMAGE}:${PRIMARY_TAG}
-Dspring-boot.build-image.imageTags=${IMAGE_TAGS}"
.maven_deploy_to_nexus:
before_script:
- !reference [ .maven_get_version, before_script ]
- export REGISTRY="$[[ inputs.nexus_image_registry ]]/${PROJECT_ARTIFACT_ID}"
- export MAVEN_DEPLOY_PROFILE="-DaltSnapshotDeploymentRepository=ozg-snapshots-nexus::default::https://nexus.ozg-sh.de/repository/ozg-snapshots/
-DaltReleaseDeploymentRepository=ozg-nexus::default::https://nexus.ozg-sh.de/repository/ozg-releases/"
.maven_deploy_image_to_nexus:
before_script:
- export MAVEN_DEPLOY_PROFILE="${MAVEN_DEPLOY_PROFILE}
-Ddocker.publishRegistry.username=${NEXUS_USER}
-Ddocker.publishRegistry.password=${NEXUS_PASSWORD}
-Ddocker.publishRegistry.url=${NEXUS_IMAGE_REGISTRY_URL}
-Dspring-boot.build-image.publish=true
-Dspring-boot.build-image.imageName=${REGISTRY}:${PRIMARY_TAG}
-Dspring-boot.build-image.imageTags=${IMAGE_TAGS}"
.maven_deploy_template:
stage: $[[ inputs.stage ]]
script:
- mvn versions:set -DnewVersion=$ARTIFACT_VERSION $[[ inputs.maven_cli_options ]]
- mvn deploy ${MAVEN_DEPLOY_PROFILE} $[[ inputs.maven_cli_options ]] $[[ inputs.maven_cli_deploy_options ]]
### Deploy Stage
"$[[ inputs.job_prefix ]]_push_merge_request_snapshot_gitlab":
extends:
- .maven_deploy_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_gitlab, before_script ]
- !reference [ .maven_get_merge_request_tags, before_script ]
- if [ "$[[ inputs.deploy_image ]]" = "true" ]; then
- !reference [ .maven_deploy_image_to_gitlab, before_script ]
- fi
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && '$[[ inputs.deploy_to_gitlab ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_merge_request_snapshot_nexus":
stage: $[[ inputs.stage ]]
extends:
- .maven_deploy_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_nexus, before_script ]
- !reference [ .maven_get_merge_request_tags, before_script ]
- if [ "$[[ inputs.deploy_image ]]" = "true" ]; then
- !reference [ .maven_deploy_image_to_nexus, before_script ]
- fi
- export REGISTRY
- export MERGE_REQUEST_TAG="${TRUNCATED_PROJECT_VERSION}-MR-${CI_MERGE_REQUEST_IID}"
- export SNAPSHOT_TAG="${TRUNCATED_PROJECT_VERSION}-${CI_COMMIT_BRANCH}"
- export MERGE_REQUEST_VERSION="${MERGE_REQUEST_TAG}-SNAPSHOT"
- export MERGE_REQUEST_IMAGE_TAG="${REGISTRY}:${MERGE_REQUEST_TAG}"
- export SNAPSHOT_IMAGE_TAG="${REGISTRY}:${SNAPSHOT_TAG}"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && '$[[ inputs.deploy_to_nexus ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_main_branch_snapshot_gitlab":
stage: $[[ inputs.stage ]]
extends:
- .maven_deploy_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_to_gitlab, before_script ]
- !reference [ .maven_get_snapshot_tags, before_script ]
- if [ "$[[ inputs.deploy_image ]]" = "true" ]; then
- !reference [ .maven_deploy_image_to_gitlab, before_script ]
- fi
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && '$[[ inputs.deploy_to_gitlab ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_merge_request_snapshot":
"$[[ inputs.job_prefix ]]_push_main_branch_snapshot_nexus":
stage: $[[ inputs.stage ]]
extends:
- .maven_deploy
- .maven_deploy_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_get_version, before_script ]
- !reference [ .maven_deploy_get_image_tags, before_script ]
script:
- mvn versions:set -DnewVersion=${MERGE_REQUEST_VERSION} $[[ inputs.maven_cli_options ]]
- export PRIMARY_IMAGE_TAG=${MERGE_REQUEST_TAG}
- export IMAGE_TAGS="${MERGE_REQUEST_IMAGE_TAG},${MERGE_REQUEST_IMAGE_TAG}-${CI_COMMIT_SHORT_SHA}"
- mvn deploy $[[ inputs.maven_profile ]] $[[ inputs.maven_cli_options ]] $MAVEN_DEPLOY_CLI_OPTIONS
- !reference [ .maven_deploy_to_nexus, before_script ]
- !reference [ .maven_get_snapshot_tags, before_script ]
- if [ "$[[ inputs.deploy_image ]]" = "true" ]; then
- !reference [ .maven_deploy_image_to_nexus, before_script ]
- fi
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
when: manual
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && '$[[ inputs.deploy_to_nexus ]]' == 'true'
"$[[ inputs.job_prefix ]]_push_main_branch_snapshot":
"$[[ inputs.job_prefix ]]_push_release_gitlab":
stage: $[[ inputs.stage ]]
extends:
- .maven_deploy
- .maven_deploy_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_get_version, before_script ]
- !reference [ .maven_deploy_get_image_tags, before_script ]
script:
- export PRIMARY_IMAGE_TAG=${SNAPSHOT_TAG}
- export IMAGE_TAGS="${SNAPSHOT_IMAGE_TAG},${SNAPSHOT_IMAGE_TAG}-${CI_COMMIT_SHORT_SHA},${REGISTRY}:snapshot-latest"
- mvn deploy $[[ inputs.maven_profile ]] $[[ inputs.maven_cli_options ]] $MAVEN_DEPLOY_CLI_OPTIONS
only:
- $[[ inputs.main_branch ]]
- !reference [ .maven_deploy_to_gitlab, before_script ]
- !reference [ .maven_get_release_tags, before_script ]
- if [ "$[[ inputs.deploy_image ]]" = "true" ]; then
- !reference [ .maven_deploy_image_to_gitlab, before_script ]
- fi
rules:
- if: $CI_COMMIT_TAG && '$[[ inputs.deploy_to_gitlab ]]' == 'true'
"$[[ inputs.job_prefix ]]_push-release":
"$[[ inputs.job_prefix ]]_push_release_nexus":
stage: $[[ inputs.stage ]]
extends:
- .maven_deploy
- .maven_deploy_job
- .maven_deploy_template
before_script:
- !reference [ .maven_deploy_get_version, before_script ]
- !reference [ .maven_deploy_get_image_tags, before_script ]
script:
- mvn versions:set -DnewVersion=${CI_COMMIT_TAG} $[[ inputs.maven_cli_options ]]
- export PRIMARY_IMAGE_TAG=${CI_COMMIT_TAG}
- export IMAGE_TAGS="${REGISTRY}:${CI_COMMIT_TAG},${REGISTRY}:latest"
- mvn deploy $[[ inputs.maven_profile ]] $[[ inputs.maven_cli_options ]] $MAVEN_DEPLOY_CLI_OPTIONS
- !reference [ .maven_deploy_to_nexus, before_script ]
- !reference [ .maven_get_release_tags, before_script ]
- if [ "$[[ inputs.deploy_image ]]" = "true" ]; then
- !reference [ .maven_deploy_image_to_nexus, before_script ]
- fi
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_TAG && '$[[ inputs.deploy_to_nexus ]]' == 'true'
\ No newline at end of file
# Maven Get Version Component
Extracts Maven project version and artifactId, and sets environment variables for use in CI pipelines.
Requires an environment variable `REGISTRY` to be set, to generate correct image tags.
## Jobs
- `.maven_get_version`
- `.maven_get_merge_request_tags`
- `.maven_get_snapshot_tags`
- `.maven_get_release_tags`
## Inputs
| Parameter | Description | Default Value |
|---------------------|---------------------------|---------------|
| `maven_cli_options` | Maven CLI options to use. | |
## Outputs (Environment Variables)
| Job | Variable | Description |
|--------------------------|-----------------------------|------------------------------------------------------------------|
| `.maven_get_version` | `TRUNCATED_PROJECT_VERSION` | The Maven project version without any suffix (e.g., `-SNAPSHOT`) |
| `.maven_get_version` | `PROJECT_ARTIFACT_ID` | The Maven artifactId |
| `.maven_get_<type>_tags` | `ARTIFACT_VERSION` | The version to use for publishing JAR artifacts |
| `.maven_get_<type>_tags` | `PRIMARY_TAG` | The main tag for images or artifacts |
| `.maven_get_<type>_tags` | `IMAGE_TAGS` | Comma-separated list of image tags, in format `registry:tag` |
## Usage Example
```yaml
include:
- component: $CI_SERVER_FQDN/ozg-cloud/devops/ci-components/maven_get_version@<version>
inputs:
maven_cli_options: >-
-s .m2/ci_settings.xml --batch-mode
-Dmaven.plugin.validation=brief
```
spec:
inputs:
maven_cli_options:
description: "Maven CLI options"
---
.maven_get_version:
before_script:
- PROJECT_VERSION="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout $[[ inputs.maven_cli_options ]])"
- export TRUNCATED_PROJECT_VERSION="$(echo "$PROJECT_VERSION" | cut -d '-' -f 1)"
- export PROJECT_ARTIFACT_ID="$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout $[[ inputs.maven_cli_options ]])"
.maven_get_merge_request_tags:
before_script:
- MERGE_REQUEST_TAG="${TRUNCATED_PROJECT_VERSION}-MR-${CI_MERGE_REQUEST_IID}"
- MERGE_REQUEST_IMAGE_TAG="${REGISTRY}:${MERGE_REQUEST_TAG}"
- export ARTIFACT_VERSION="${MERGE_REQUEST_TAG}-SNAPSHOT"
- export PRIMARY_TAG="${MERGE_REQUEST_TAG}"
- export IMAGE_TAGS="${MERGE_REQUEST_IMAGE_TAG},${MERGE_REQUEST_IMAGE_TAG}-${CI_COMMIT_SHORT_SHA}"
.maven_get_snapshot_tags:
before_script:
- SNAPSHOT_TAG="${TRUNCATED_PROJECT_VERSION}-${CI_COMMIT_BRANCH}"
- SNAPSHOT_IMAGE_TAG="${REGISTRY}:${SNAPSHOT_TAG}"
- export ARTIFACT_VERSION="${TRUNCATED_PROJECT_VERSION}-SNAPSHOT"
- export PRIMARY_TAG=${SNAPSHOT_TAG}
- export IMAGE_TAGS="${SNAPSHOT_IMAGE_TAG},${SNAPSHOT_IMAGE_TAG}-${CI_COMMIT_SHORT_SHA},${REGISTRY}:snapshot-latest"
.maven_get_release_tags:
before_script:
- export ARTIFACT_VERSION="${CI_COMMIT_TAG}"
- export PRIMARY_TAG=${CI_COMMIT_TAG}
- export IMAGE_TAGS="${REGISTRY}:${CI_COMMIT_TAG},${REGISTRY}:latest"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment