Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying maven artifacts without rebuilding

We are using declarative pipeline, latest Jenkins. Builds are executed in a docker slave container, which has maven and other tools. Our current Jenkinsfile resembles this:

stage('build') { steps { sh 'mvn clean install'} }
stage('test') { /* functional tests using a different tool */ }
stage('publish') { 
    steps {
      // mvn clean deploy -DskipTests -DaltDeploymentRepository... (rebuilds, which we want to avoid, as its a multimodule project)
      // withMaven(options:[artifactsPublisher()] { } ... (from maven-pipeline-plugin)
    }
}

Jenkins classic mode has a Maven Integration plugin which provides a section "Deploy artifacts to Maven repository" which uses Maven RedeployPublisher to only publish artifacts. I am looking for a pipeline equivalent of this, I thought the maven-pipeline-plugin does this, but cant find an example. Any pointers appreciated!

like image 449
vasya10 Avatar asked Aug 17 '17 15:08

vasya10


People also ask

Does mvn deploy also build?

The deploy is the last phase of the maven lifecycle. In this phase, the build is completed and the current project is being copied to the remote repository. This makes the built project available for other projects to add as dependency or developers.

What does mvn deploy do?

The deploy plugin is primarily used during the deploy phase, to add your artifact(s) to a remote repository for sharing with other developers and projects. This is usually done in an integration or release environment.


1 Answers

I stumbled upon your question looking for the same thing, and what worked for me was this:

stage('Deploy') {
    sh "'${mvnHome}/bin/mvn' war:war deploy:deploy"
}

Of course, you need to change war:war to the type of the artifact that you want to deploy (so jar:jar or ear:ear). I found this basing on this answer, but it seems to be relevant to maven-war-plugin, as well as to maven-jar-plugin, although there is no forceCreation option in the war goal.

like image 75
bushi Avatar answered Sep 22 '22 13:09

bushi