Visualizing each maven stage as a separate gitlab job without re-running previous maven stages

I currently have these gitlab stages outlined below in my .gitlab-ci.yml

I created it this way to visualize in gitlab each maven stage in the pipeline. however, because maven automatically executes preceding stages in the build life cycle it means i’m wasting a lot of time and cpu in the test and deploy gitlab stages because these re-execute their preceding maven stages.

Is it possible for gitlab and maven to play nicely so I can visualize each maven stage visually in gitlab without maven re-executing previous stages in the build lifecycle and instead use the artifacts from the previous job in the pipeline?

Or, do I need to just consolidate the three stages into a single, ‘mvn clean deploy -U’ stage?

stages:

  • build
  • test
  • deploy

build:
tags:

  • core
    variables:
    GIT_STRATEGY: fetch
    stage: build
    script:
  • echo ‘Building’
  • mvn $MAVEN_CLI_OPTS -T 4 clean install -U

test:
tags:

  • core
    stage: test
    script:
  • echo ‘Testing’
  • mvn $MAVEN_CLI_OPTS test

deploy:
tags:

  • core
    artifacts:
    expire_in: 1 week
    when: always
    paths:
    • target/*
      variables:
      GIT_STRATEGY: none
      stage: deploy
      script:
  • echo ‘Deploying to Nexus’
  • ‘mvn $MAVEN_CLI_OPTS deploy -U’

Hi Steve

Did you ever get an answer to this one or find a way how to achieve the one stage in the pipeline file configuration while displaying all the maven phases as stages in the web gui pipeline view?

Coming to think of it, one could do this:

mvn::test:
  stage: mvn
  script: mvn test
mvn::package:
  stage: mvn
  script: mvn package
mvn::install:
  stage: mvn
  script: mvn install
...

You would not save the CPU cycles but time since all jobs start in parallel. With this approach one could still see all the pipeline stages/maven phases in the pipeline view and where the build failed if that is the case.

Thanks. I just decided to go with sequential jobs and ensure the cache is used from the previous stage.