I'm working on a multi-branch pipeline for a maven project. I'm trying to follow what the Jenkins docs keep referring to as the standard CI steps, Build, Test, Deploy. But maven doesn't seem to work very well with treating these as discreet steps.
I have this so far:
stages {
stage('Test') {
steps {
sh "mvn -B clean verify"
}
}
stage('Deploy') {
when {
branch 'master'
}
steps {
sh "mvn -B deploy"
}
}
}
With this, the full build is going to run twice, once in the Test stage and again in the Deploy stage. That isn't great as it's a time consuming build thanks to Google Web Toolkit, but that's a separate issue.
Is there a way to gracefully skip the earlier maven lifecycle steps in the Deploy stage and skip to the deploy goal?
The only other alternative I can think of is
stages {
stage('Test') {
when {
// Some expression that states "not master"
}
steps {
sh "mvn -B clean verify"
}
}
stage('Test-and-Deploy') {
when {
branch 'master'
}
steps {
sh "mvn -B deploy"
}
}
}
I'm not happy with that either due to how this is rendered in the Jenkins UI, and it feels odd to compress what the Jenkins documentation implies should be 3 stages into a single stage. I figure it's the lesser evil though, so I'll probably go with that unless I can find something better.
Maven lifecycle runs all steps that are preconditions to what you execute. Lifecycle looks like this:
process-resources
compile
process-test-resources
test-compile
test
package
install
deploy
So compile will run process-resources and so on.
If you want to execute a single goal, you need to specify it using the plugin:goal syntax, like this:
compile:compile
In your case, to execute only deploy, you need to do mvn deploy:deploy.
For detailed description of maven lifecycle and goals, please see the official docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With