7
votes

I have configured a Jenkins job to build a Maven 3 project and with the "Maven release build" plugin enabled and also added a post-build action to deploy the artifacts to a Nexus repository.

However, I don't want artifacts to be deployed unless the user had initiated the build by clicking the "Perform Maven Release" link instead of the "Build Now" button. When the click "Build Now" I just want a snapshot build that doesn't get deployed anywhere.

I understood from the documentation that I could use a environment variable called IS_M2RELEASEBUILD to control this behavior. This environment variable is set to true by the M2 Release Plugin when the build was initiated via the "Perform Maven release" link. But the post build action is completely ignoring this.

Jenkins Settings

I am using Jenkins LTS 1.509.3 and Maven 3.0.5.

UPDATE: Please note that I am not looking for a workaround using using the Maven Release Plugin within the POM. My goal is to create a single Jenkins job that acts as the CI build (without deploying the snapshot) triggered by check-ins and to be able to use the same job to perform a release build using the Jenkins M2 Release plugin.

3
How about changing the version to SNAPSHOT and define the snapshot repository?Abhijith Nagarajan
@AbhijithNagarajan I don't see a way to have 2 post-build actions (one for release and one for snapshot) and I think I would have a similar problem finding a way to conditional execute one or the other. Besides I don't want to actually deploy the snapshot artifacts.Brian Matthews
@AlexanderKudrevatykh If I was to use Maven to deploy the artifacts then I need two jobs. One for the release build and one for the CI build. I am trying to avoid having to maintain two jobs for every component that is versioned and released independently.Brian Matthews
can't you add the deploy goal to the release goals? I would guess that it will then only be executed, if it is an release.Peter Schuetze
Using the configuration in the pom is not a "workaround"; you are implicitly using the maven-release-plugin when the Jenkins job executes the "release:prepare release:perform" actions. "This plugin allows you to perform a release build using the maven-release-plugin from within Jenkins." If you really don't want to do it in the pom you can probably just append -Dgoals=deploy to the "Release goals and options" section, but I can't think of a single reason not to put it in the pom. It won't have any impact until you call one of the release goals in your jenkins job.Zac Thompson

3 Answers

2
votes

Take a look on Flexible Publish Plugin:

I think you can easily check your environment variable against required pattern

enter image description here

and trigger proper post build action (sorry, do not have deploy to maven)

enter image description here

1
votes

If you add the deploy action to the maven release goals then you don't need a separate step in the Jenkins job. These goals are only executed on release:perform. Something like:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-release-plugin</artifactId>
  <configuration>
    <goals>deploy</goals>
  </configuration>
</plugin>

Peter Schuetze answered this in the comments and should probably post this answer to get the bounty.

1
votes

My Comment to the question is apparently the answer. ;)

can't you add the deploy goal to the release goals? I would guess that it will then only be executed, if it is an release.