How to ignore SNAPSHOTs on Maven versions:set?

149 views Asked by At

I would like to have Maven build Java projects on our Jenkins server. The version should be set correctly in the pom.xml. For this I use in the PreBuild Step:

mvn build-helper:parse-version versions:set -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.##JenkinsBuildNumber##

0.3.12
0.5.56 etc.

It will now build the version correctly.

But now I notice that from SNAPSHOTs now also normal versions are built:

1.0-SNAPSHOT => 1.0.12
2.0-SNAPSHOT => 2.0.54

Of course this should not be. Best no version is to be adapted with SNAPSHOTS at all, thus Ignoriert. But this does not work:

mvn build-helper:parse-version versions:set -DignoredVersions=.*-SNAPSHOT -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.##JenkinsBuildNumber##

The build number is still appended. How can I get versions:set to not change the version on SNAPSHOTs?

1.0-SNAPSHOT => 1.0-SNAPSHOT
2.0-SNAPSHOT => 2.0-SNAPSHOT
0.3.0 => 0.3.12
0.5.0 => 0.5.56
1.2.0 => 1.2.124
1

There are 1 answers

0
Burner On BEST ANSWER

I solved it with a Pre-Build Step

Conditional Step
Execute Shell
ACTUALVERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) && if echo ${ACTUALVERSION} | test=$(grep -v "SNAPSHOT"); then exit 0; else exit 1; fi

Run Maven Goal

build-helper:parse-version versions:set -DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}${parsedVersion.qualifier?}.${BUILD_NUMBER}