0

I'm using the gradle-release-plugin in Bamboo, with the option useAutomaticVersion=true, to add a git tag and then auto increment version number. The default behavior of the gradle-release-plugin is to increment the patch version (2.0.3 -> 2.0.4). I am trying to implement the following use-case:

  1. If the current branch is master then increment the minor version (2.0.3 -> 2.1.0)
  2. If the current branch is any other branch but master, then increment the patch version (2.0.3 -> 2.0.4)

I was wondering if gradle-release-plugin can provide such a functionality?

Rustam Issabekov
  • 3,279
  • 6
  • 24
  • 31

1 Answers1

1

The plugin itself doesn't really provide that but you can get it with your own version matcher.

String getCurrentBranch(Project p) {
    OutputStream out = new ByteArrayOutputStream()
    p.exec {
        commandLine = ['git', 'rev-parse', '--abbrev-ref', 'HEAD']
        workingDir = projectToCheck.rootProject.projectDir
        standardOutput = out
    }
    return out.toString().trim()
}
release {
    versionPatterns = [
            /(\d+)\.(\d+)\.(\d+)/: { Matcher m, Project p ->
                if (getCurrentBranch(p) == 'master') {
                    m.replaceAll("${m[0][1]}.${(m[0][2] as int) + 1}.0")
                } else {
                    m.replaceAll("${m[0][1]}.${m[0][2]}.${(m[0][3] as int) + 1}")
                }
            }
    ]
}

Didn't tested the code but that's the way I would go.

Hillkorn
  • 633
  • 4
  • 12