javamavengitlabmaven-release-plugin

maven release plugin fails second time on gitlab


I setup a pipeline on gitlab but I get a weird error "You don't have a SNAPSHOT project in the reactor projects list"

I'm just trying to deploy a java spring boot. Below the pom.xml (only what's relevant)

<name>Project Phoenix - Base</name>
<groupId>com.gfs</groupId>
<artifactId>phoenix</artifactId>
<version>1.12-SNAPSHOT</version>
<packaging>pom</packaging>

...

<scm>
    <developerConnection>scm:git:${project.scm.url}</developerConnection>
    <url>git@gitlab.com:"myuser"/phoenix.git</url>
    <tag>HEAD</tag>
</scm>
....
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>${maven.release.plugin}</version>
            <configuration>
                <scmDevelopmentCommitComment>@{prefix} prepare for next development iteration [skip ci]</scmDevelopmentCommitComment>
            </configuration>
        </plugin>

My gitlab-ci.yml looks like this:

workflow:
  rules:
    - if: $CI_COMMIT_TAG
      when: never
    - if: $CI_COMMIT_BRANCH == 'master'

variables:
  MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
  MAVEN_CLI_OPTS: "-s settings.xml --batch-mode --errors --fail-at-end --show-version"
  MAVEN_IMAGE: maven:3.8.5-openjdk-17-slim

services:
  - docker:dind

stages:
  - build
  - release

cache:
  paths:
    - .m2/repository/
    - target/

build-job:
  image: $MAVEN_IMAGE
  stage: build
  script:
    - echo "Building $MODULE"
    - mvn clean package -B $MAVEN_CLI_OPTS
 
release-job:
  image: $MAVEN_IMAGE
  stage: release
  tags:
    - local-runner
  before_script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - apt-get update -qq
    - apt-get install -qq git
    - git config --global user.email "hidden"
    - git config --global user.name "hidden"
    - git checkout -B "$CI_COMMIT_REF_NAME"
  script:
    - echo "Creating the release"
    - mvn $MAVEN_CLI_OPTS clean deploy release:prepare release:perform
  only:
    - master

After I push, gitlab starts a pipeline on the commit which is successful and it deploys in the gitlab package registry the snapshot and the release. However, there are other 2 pipeline starting [maven-release-plugin] which it seems it does the same things but it fails:

First it says:

Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch)

Then it says: You don't have a SNAPSHOT project in the reactor projects list

$ git checkout -B "$CI_COMMIT_REF_NAME"
Switched to and reset branch 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)
$ echo "Creating the release"
Creating the release
$ mvn $MAVEN_CLI_OPTS clean deploy release:prepare release:perform
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /usr/share/maven
Java version: 17.0.2, vendor: Oracle Corporation, runtime: /usr/local/openjdk-17
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.10.104-linuxkit", arch: "aarch64", family: "unix"
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.gfs:phoenix >---------------------------
[INFO] Building Project Phoenix - Base 1.11
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ phoenix ---
[INFO] Deleting /builds/gfalco77/phoenix/target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:prepare-agent (default) @ phoenix ---
[INFO] argLine set to -javaagent:/builds/gfalco77/phoenix/.m2/repository/org/jacoco/org.jacoco.agent/0.8.8/org.jacoco.agent-0.8.8-runtime.jar=destfile=/builds/gfalco77/phoenix/target/jacoco.exec
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.6.7:repackage (repackage) @ phoenix ---
[INFO] 
[INFO] --- maven-failsafe-plugin:3.0.0-M6:integration-test (default) @ phoenix ---
[INFO] No tests to run.
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.8:report (report) @ phoenix ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO] 
[INFO] --- maven-failsafe-plugin:3.0.0-M6:verify (default) @ phoenix ---
[INFO] Failsafe report directory: /builds/gfalco77/phoenix/target/failsafe-reports
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ phoenix ---
[INFO] Installing /builds/gfalco77/phoenix/pom.xml to /builds/gfalco77/phoenix/.m2/repository/com/gfs/phoenix/1.11/phoenix-1.11.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ phoenix ---
[INFO] Uploading to gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/1.11/phoenix-1.11.pom
[INFO] Uploaded to gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/1.11/phoenix-1.11.pom (6.5 kB at 2.2 kB/s)
[INFO] Downloading from gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/maven-metadata.xml
[INFO] Downloaded from gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/maven-metadata.xml (361 B at 334 B/s)
[INFO] Uploading to gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/maven-metadata.xml
[INFO] Uploaded to gitlab-maven: https://gitlab.com/api/v4/projects/36116501/packages/maven/com/gfs/phoenix/maven-metadata.xml (361 B at 111 B/s)
[INFO] 
[INFO] --------------------------< com.gfs:phoenix >---------------------------
[INFO] Building Project Phoenix - Base 1.11
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-release-plugin:3.0.0-M5:prepare (default-cli) @ phoenix ---
[INFO] phase verify-release-configuration
[INFO] starting prepare goal, composed of 17 phases: check-poms, scm-check-modifications, check-dependency-snapshots, create-backup-poms, map-release-versions, input-variables, map-development-versions, rewrite-poms-for-release, generate-release-poms, run-preparation-goals, scm-commit-release, scm-tag, rewrite-poms-for-development, remove-release-poms, run-completion-goals, scm-commit-development, end-release
[INFO] [prepare] 1/17 check-poms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.246 s
[INFO] Finished at: 2022-07-13T16:57:18Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M5:prepare (default-cli) on project phoenix: You don't have a SNAPSHOT project in the reactor projects list. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:3.0.0-M5:prepare (default-cli) on project phoenix: You don't have a SNAPSHOT project in the reactor projects list.

The third and last pipeline is [maven-release-plugin] prepare for next development iteration [skip ci] which is Skipped..

Does anybody know what it should happen, why does it complain on the snapshot?

Thanks


Solution

  • Basically, if not that error you would run in infinite loop :) The release:prepare performs the following steps:

    So, upon completion of your CI pipeline you are getting two new commits into master branch:

    [maven-release-plugin] prepare for next development iteration
    [maven-release-plugin] prepare release XXX
    

    which in turn triggers your CI pipeline again, you just need to disable pipeline triggering for specific CI_COMMIT_MESSAGE (or setup scmReleaseCommitComment, which actually looks not so good as well as scmDevelopmentCommitComment)


    UPD.

    I have revised your release pipeline I can definitely say everything you are doing is wrong. The main problem is you are trying to implement release pipeline relying on suggestions from internet (e.g. what you have provided looks very similar to https://forum.gitlab.com/t/getting-mvn-release-to-work-with-gitlab-ci/4904) instead of basing on best practices and common sense...

    1. what is the purpose of the following code snippet?
    stages:
      - build
      - release
    
    ...
    build-job:
      image: $MAVEN_IMAGE
      stage: build
      script:
        - echo "Building $MODULE"
        - mvn clean package -B $MAVEN_CLI_OPTS
    
    ...
    release-job:
      stage: release
    ...
      script:
        - echo "Creating the release"
        - mvn $MAVEN_CLI_OPTS clean deploy release:prepare release:perform
    

    so, in your release pipeline you perform compile and test three times, and verify two times, which actually sounds good for your SaaS provider: more resources you consume - more money you spend.

    1. following code snippet:
      before_script:
        - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
        - eval $(ssh-agent -s)
        - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
        - mkdir -p ~/.ssh
        - chmod 700 ~/.ssh
        - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
        - apt-get update -qq
        - apt-get install -qq git
        - git config --global user.email "hidden"
        - git config --global user.name "hidden"
    

    actually assumes you supposed to create your own docker images which contains jdk, maven, ssh, git and other toolchain stuff.

    1. following code snippet:
      before_script:
    ...
        - git checkout -B "$CI_COMMIT_REF_NAME"
    

    reveals that Gitlab is neither CI nor CD, the question is: what commit your release is based on? The answer is: on something after my commit :)