3
votes

I'm having a Jenkins with the M2 release plugin. I have a job for building AND releasing.

The used repository has master and feature/bugfix branches. The job is configured to build all branches. The master branch is deployed in addition. All stable changes are merged into master branch but the latest changes (not working yet) are made in a bugfix branch. Therefore the latest build (mvn install) is made on this bugfix branch.

If I want to release this project jenkins takes the latest built revision (the bugfix branch) and tries to release this. Due to SNAPSHOT dependencies this is failing.

I could of course set the "branch to build" to "master" when releasing. But a) I would need to reset this after release and b) this would be necessary everytime i want to release.

I also could make this build parameterized with branch options but then this job will not be executed by scm commits.

So my question is: Is there a way/plugin to tell jenkins to release a specific branch?

EDIT: I added my pom.xml so you might be able to provide an easy to understand example

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>my.parent.gid</groupId>
    <artifactId>my.iarent.aid</artifactId>
    <version>1.0.0</version>
</parent>

<name>Project Name</name>

<groupId>my.project.gid</groupId>
<artifactId>my.project.aid</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<url>${project_url}</url>

<ciManagement>
    <system>${project_ciManagement.system}</system>
    <url>${project_ciManagement.url}</url>
</ciManagement>

<scm>
    <!-- read access -->
    <connection>${project_scm.connection}</connection>
    <!-- write access (release-plugin) -->
    <developerConnection>${project_scm.developerConnection}</developerConnection>
    <!-- browser access -->
    <url>${project_scm.url}</url>
    <tag>HEAD</tag>
</scm>

<properties>
    <compiler.javaVersion>1.7</compiler.javaVersion>
    <scm.repo>repo_name</scm.repo>
</properties>

<modules>
    <module>Module1</module>
    <module>Module2</module>
    <module>Module3</module>
</modules>

2

2 Answers

0
votes

In the config of the Jenkins job, you can specify the branch something like:

release_*

And then enter a version number as part of the Build With Parameters option each time you build, which will then build from release_{number} branch.

In this way, you don't have to edit the Jenkins job every time.

0
votes

Keep the pom on your release branch as it should be:

<groupId>my.project.gid</groupId>
<artifactId>my.project.aid</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

When you do mvn release:prepare it will tag SCM as 1.0.0 and change the version in the pom to 1.0.1-SNAPSHOT ready for the next iteration.

mvn release:perform will then get the tag 1.0.0, build and push the artifact to your repository, Nexus or similar.

Your feature branches should have poms like:

<groupId>my.project.gid</groupId>
<artifactId>my.project.aid</artifactId>
<version>1.0.0-SP123-SNAPSHOT</version>
<packaging>pom</packaging>

Where SP123 is the story of similar. You will not release from this branch so the versions are not important.

When your release manager does the merge of the feature branch into the release branch they should fix the version.