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

OZG-8085 Maven deploy component

parent c6565f6d
Branches
Tags
No related merge requests found
......@@ -6,3 +6,7 @@
### Maven Build
Build and test Maven projects.
### Maven Deploy
Deploy Maven build artefacts.
Provides Jobs for Merge Requests, main-Branch Snapshots and Releases on Git Tags.
......@@ -7,9 +7,8 @@ spec:
default: build
test_stage:
default: test
maven_cli_opts:
maven_cli_options:
description: "Maven CLI options"
---
cache:
paths:
......@@ -19,7 +18,7 @@ cache:
"$[[ inputs.job_prefix ]]_build":
stage: $[[ inputs.build_stage ]]
script:
- mvn clean compile $[[ inputs.maven_cli_opts ]] --update-snapshots
- mvn clean compile $[[ inputs.maven_cli_options ]] --update-snapshots
artifacts:
paths:
- target/*.jar
......@@ -27,9 +26,9 @@ cache:
"$[[ inputs.job_prefix ]]_test":
stage: $[[ inputs.test_stage ]]
script:
- mvn test $[[ inputs.maven_cli_opts ]]
- mvn test $[[ inputs.maven_cli_options ]]
"$[[ inputs.job_prefix ]]_verify":
stage: $[[ inputs.test_stage ]]
script:
- mvn verify $[[ inputs.maven_cli_opts ]]
\ No newline at end of file
- 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.
## Jobs
- Manual Job for publishing 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` |
| `maven_cli_options` | Maven options to pass to the maven commands. | |
| `maven_profile` | | |
| `image_registry` | | |
| `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` |
## Usage Example
```yaml
include:
- component: $CI_SERVER_FQDN/ozg-cloud/devops/ci-components/maven_deploy@<version>
inputs:
maven_cli_opts: >-
-s .m2/ci_settings.xml --batch-mode
-Dmaven.plugin.validation=brief
maven_profile: "-Pgitlab-deploy"
```
\ No newline at end of file
spec:
inputs:
job_prefix:
description: "Define a prefix for the job name"
default: "maven"
stage:
default: publish
maven_cli_options:
description: "Maven CLI options"
maven_profile:
description: "Maven profile to activate"
default: ""
image_registry:
description: "URL "
default: ""
append_artifact_id_to_registry:
description: "Whether to append the artifact ID to the Registry URL (boolean)"
default: false
main_branch:
default: "main"
---
variables:
MAVEN_DEPLOY_CLI_OPTIONS: "--no-transfer-progress -DskipTests"
".$[[ inputs.job_prefix ]]_get_version":
before_script:
- PROJECT_VERSION="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout $MAVEN_CLI_OPTS)"
- export TRUNCATED_PROJECT_VERSION="$(echo "$PROJECT_VERSION" | cut -d '-' -f 1)"
- export PROJECT_ARTIFACT_ID="$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout $MAVEN_CLI_OPTS)"
".$[[ inputs.job_prefix ]]_get_image_tags":
before_script:
- if [ $[[ inputs.append_artifact_id_to_registry ]] = true ]; then
- REGISTRY="[[ inputs.image_registry ]]/${PROJECT_ARTIFACT_ID}"
- else
- REGISTRY="$[[ inputs.image_registry ]]"
- 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}"
"$[[ inputs.job_prefix ]]_push_merge_request_snapshot":
stage: $[[ inputs.stage ]]
before_script:
- !reference [ ".$[[ inputs.job_prefix ]]_get_version", before_script ]
- !reference [ ".$[[ inputs.job_prefix ]]_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
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
when: manual
"$[[ inputs.job_prefix ]]_push_main_branch_snapshot":
stage: publish
before_script:
- !reference [ ".$[[ inputs.job_prefix ]]_get_version", before_script ]
- !reference [ ".$[[ inputs.job_prefix ]]_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 ]]
"$[[ inputs.job_prefix ]]_push-release":
stage: publish
extends: .get-version
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
rules:
- if: $CI_COMMIT_TAG
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment