Is there a more efficient way to take the last number (patch version) of a tag version?

Is there a more efficient way to take the last number (patch version) of a tag version?

Context: I’m trying to extract a version number from a Dockerfile and extract the patch version from it and use this for a new version tag. Example:


And need to extract the 10 from the version above.

So far this works fine:

    def dockerfile = readFile "Dockerfile"
    imageVersion = dockerfile.find(/([A-Za-z]+(-[A-Za-z]+)+):[\d.]+/)
    version = imageVersion.find(/[\d.]+/)

And the output would be 3.1.10.

In order to extract the 10 I thought that this could work but Jenkins complains about the *.toInteger() part.

def mvnVersion = "20.14.2"
versionTag = version.split("\\.")*.toInteger()
masterVersion = mvnVersion + "." + versionTag.get(2)

So that the output would be something like but I’m getting the following error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 20: spread not yet supported for CPS transformation @ line 20, column 30.
                   versionTag = version.split("\\.")*.toInteger()

1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(
	at org.codehaus.groovy.control.CompilationUnit.compile(
	at groovy.lang.GroovyClassLoader.doParseClass(
	at groovy.lang.GroovyClassLoader.parseClass(
	at groovy.lang.GroovyShell.parseClass(
Finished: FAILURE

Any suggestions are welcomed. Thanks in advance!!