gradle-release
gradle-release copied to clipboard
How can I change the version in every run?
This is more a question than an issue. I see that I can call the release task to set the new version and everything will be done accordingly with the expected behavior.
But, I would like to have this in the Jenkins and every time a successful build runs, I want to change the version without changing Jenkins pipeline. How can I do this? Ex: I'm working on version 0.0.1.0 and I want to generate version 0.0.1.1, .2 and so on.
From time to time, I want also to change a major/minor version, and manually I run a release to change from 0.0.1 to 0.0.2.0 and the plugin should continue the numbering (.1, .2...)
First thing that comes to my mind is that jenkins probably runs into an infinite loop as the plugin pushes the changes to remote which might trigger another build? It should be possible what you want by using the versionPattern config
versionPatterns = [
/(\d+)([^\d]*$)/: { Matcher m, Project p -> m.replaceAll("${(m[0][1] as int) + 1}${m[0][2]}") }
]
and also running gradle via gradle release -Prelease.useAutomaticVersion=true
in your jenkins job.
But I think the versionPattern then should be something like
versionPatterns = [
([\d+\.]+)([\d+])(\.\d+)$: { Matcher m, Project p -> m.replaceAll("${m[0]}${(m[1] as int) + 1}${[2]}") }
]
Didn't testet the pattern but something like that should do the trick. It checks if the pattern given as a key matches on version upgrade and executes the closure on it. The return value is the new version.