How to skip preceding maven goals in gitlab-ci build?
I have a java webservice and want to set separate test/build/deploy stages in gitlab-ci
.
A flow would probably be simple as follows:
stages:
- test
- build
- deploy
test:
stage: clean test
script:
- mvn $MAVEN_CLI_OPTS test
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS package -DskipTests=true
deploy:
stage: deploy
script:
- mvn $MAVEN_CLI_OPTS package -DskipTests=true
Problem: each maven goal will execute the preceding lifecycle goals. Eg a package
or deploy
goal will by default also execute the test
goal. Thus having to exclude it explicit with skipTests=true
.
Anyways goals like package
will still be re-executed on test + deploy.
Question: can this be further optimized? I mean, I would not want to rebuild the jar on each stage. Could I tell maven to reuse the jar, and skip any preceding goals?
I know that a single deploy
stage would be sufficient for maven to execute the package and test goal under the hood. But then in my gitlab I’d always have failures in the deploy
stage, while eg just a junit test in the test
goal failed underneath.
Source: Docker Questions