Created
May 27, 2026 16:32
-
-
Save jprinet/596d9c2f11f6232567a92a0b9cd95647 to your computer and use it in GitHub Desktop.
Artifact Cache CLI / Maven template for GitLab CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Artifact Cache CLI / Maven template for GitLab CI | |
| # | |
| # Adapted from the official GitHub Actions example at: | |
| # https://docs.gradle.com/develocity/artifact-cache/1.1/how-to/configure-github-actions/#complete-workflow-example | |
| # | |
| # Required CI/CD variables (Settings -> CI/CD -> Variables, masked + protected): | |
| # - ARTIFACT_CACHE_REPO_USERNAME | |
| # - ARTIFACT_CACHE_REPO_PASSWORD | |
| # | |
| # DEVELOCITY_ACCESS_KEY is expected to be injected as a masked env var at the | |
| # group/instance level - no per-project configuration needed. | |
| stages: | |
| - build | |
| variables: | |
| # Artifact Cache configuration | |
| ARTIFACT_CACHE_CLI_VERSION: "1.1.0" | |
| ARTIFACT_CACHE_IMAGE: "<your-image-name>" | |
| # Develocity | |
| DV_SERVER: "https://<your-develocity-server>" | |
| # Full URL to the Artifact Cache CLI jar | |
| ARTIFACT_CACHE_CLI_URL: "https://<your-repo>/path/to/develocity-artifact-cache-cli-1.1.0.jar" | |
| # Misc | |
| ARTIFACT_CACHE_OPTS: "" | |
| ARTIFACT_CACHE_TOOL_DIR: "${CI_PROJECT_DIR}/.tools/develocity/artifact-cache" | |
| build: | |
| stage: build | |
| image: maven:3.9-eclipse-temurin-21 | |
| cache: | |
| key: artifact-cache-cli-$ARTIFACT_CACHE_CLI_VERSION | |
| paths: | |
| - .tools/develocity/artifact-cache/ | |
| policy: pull-push | |
| before_script: | |
| - | | |
| set -euo pipefail | |
| JAR_PATH="${ARTIFACT_CACHE_TOOL_DIR}/${ARTIFACT_CACHE_CLI_VERSION}/develocity-artifact-cache-cli.jar" | |
| mkdir -p "$(dirname "$JAR_PATH")" | |
| if [ ! -f "$JAR_PATH" ]; then | |
| echo "Downloading Artifact Cache CLI v${ARTIFACT_CACHE_CLI_VERSION}..." | |
| curl --location --fail --silent --show-error \ | |
| --connect-timeout 5 --max-time 30 \ | |
| --retry 3 --retry-delay 3 --retry-max-time 60 \ | |
| --user "${ARTIFACT_CACHE_REPO_USERNAME}:${ARTIFACT_CACHE_REPO_PASSWORD}" \ | |
| "${ARTIFACT_CACHE_CLI_URL}" \ | |
| --output "$JAR_PATH" | |
| fi | |
| export ARTIFACT_CACHE_CMD="java -jar $JAR_PATH" | |
| export ARTIFACT_CACHE_CMD_OPTS="--dv-server=${DV_SERVER} ${ARTIFACT_CACHE_IMAGE:+--image-name=${ARTIFACT_CACHE_IMAGE}} ${ARTIFACT_CACHE_OPTS}" | |
| script: | |
| # Restore - warn but do not fail | |
| - | | |
| $ARTIFACT_CACHE_CMD restore $ARTIFACT_CACHE_CMD_OPTS \ | |
| || echo "WARNING - Could not restore the Artifact Cache. The build will proceed but may be slower." | |
| # Build (uses the default ~/.m2/repository, which is what the CLI restored into) | |
| - mvn clean package | |
| # Store - warn but do not fail | |
| - | | |
| $ARTIFACT_CACHE_CMD store $ARTIFACT_CACHE_CMD_OPTS \ | |
| || echo "WARNING - Failed to store in the Artifact Cache." | |
| after_script: | |
| # Move the CLI log into the workspace so GitLab can publish it as an artifact. | |
| - cp -f ~/.develocity/artifact-cache/artifact-cache.log artifact-cache.log 2>/dev/null || true | |
| artifacts: | |
| when: always | |
| expire_in: 7 days | |
| paths: | |
| - artifact-cache.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment