15

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!

vasya10
  • 599
  • 6
  • 19
  • The problem you are faced is that the maven life cycle runs all steps in case of using `deploy` which includes the `install` phase...The question is what kind of tool you are using for functional tests? Why not using integration-test phase of Maven ? – khmarbaise Aug 17 '17 at 18:06
  • @khmarbaise yes and the install phase is what we want to avoid. The functional tests is also mvn based but has to run independently from compilation for other reasons. – vasya10 Aug 17 '17 at 22:58
  • @vasya10 did you manage to solve the problem? – filip Jan 08 '18 at 09:11
  • @filip not the way we wanted to. we continue to use mvn clean deploy command and skip tests, yes it rebuilds but publishes correctly. – vasya10 Jan 18 '18 at 20:11

1 Answers1

5

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.

bushi
  • 51
  • 5
  • 2
    In this way you deploy only the specified artifacts? How would you deploy (without rebuilding) all artifacts (jars, zip,...) of a multi-module project? – filip Jan 08 '18 at 09:12
  • 3
    I'm afraid that this doesn't work for multi-module projects. My suggestion would be to use `mvn deploy -DskipTests` (without `clean` phase) after `mvn clean install`. – bushi Jan 10 '18 at 07:07
  • 1
    @bushi While `mvn deploy -DskipTests` works it rebuilds the entire project. It's really ironic that Maven and Jenkins integrate so poorly. – Jasper Siepkes Apr 12 '23 at 14:33