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:
Dockerfile
FROM xxxx.com/base-image:3.1.10
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 20.14.2.10
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(ErrorCollector.java:309)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1107)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:624)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:323)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:293)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:677)
...
Finished: FAILURE
Any suggestions are welcomed. Thanks in advance!!