artifactVersion = getVersion('build.gradle')
println artifactVersion[enter image description here][1]
def getVersion(String fileName) {
readFile(env.WORKSPACE+"/"+fileName).split("\n").each { line ->
if ((line =~ /version (.*)/).count > 0) {
echo line
def m = (line =~ /version (.*)/)[0]
echo m[1].replaceAll('"','').toString()
println m[1].replaceAll('-SNAPSHOT','').toString()
return m[1].replaceAll('-SNAPSHOT','').toString()
}
}
}
from getVersion api am getting the version 1.0 and that am attached in the console but that 1.0 is not appending to the artifactVersion
One problem in your code is that the return in getVersion does not return out of the function.
The curly braces in list.each{ }
create an anonymous function. Calling return inside will only return from the current iteration of the each function. A normal for loop or a combination of find/findAll and collect (map in other languages) would be better.
See also Groovy Closures and list methods .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.