Is that possible to use Kotlin features with placeholders?
My current task is to improve our CI/CD pipelines with proper versioning. Here are some details:
For example, I have some java project which consists of pom.xml, some sources, dockerfile and etc. If pom.xml <version> field contains SNAPSHOT label (example: 0.0.1-SNAPSHOT), i need to properly define version of docker image which will be builded a few build steps later. So in this case i'd like to split %maven.project.version% variable (which will be filled by maven build step right before) with delimiter "-" and take first element from result.
But it looks like that placeholder %maven.project.version% becomes "0.0.1-SNAPSHOT" AFTER it executes *.split method, So i do not receive what i want, instead, i receive list with one element: ["0.0.1-SNAPSHOT"].
So here is my question. If i understand this correct, in pipeline, Kotlin functions executed before placeholders change. Is that so? And, if im doing everything right, how could i make what i want?
Here is some examples from my code:
fun versionCheck(mvnProjectVersion: String): String {
return mvnProjectVersion.split("-")[0]
}
steps {
maven {
name = "Java artifact package"
goals = "clean install"
//dockerImage = "maven:3.6.3-openjdk-8"
//dockerPull = true
runnerArgs = "-X"
enabled = true
}
val mvnProjectVersion = "%maven.project.version%"
val delimiter = "-"
val arrayOfPackageVersion = mvnProjectVersion.split(delimiter)
script {
scriptContent = """echo %maven.project.version%
|echo %maven.project.version%
|echo ${mvnProjectVersion.split("-")}
|echo ${mvnProjectVersion.split("-")[0]}
|echo ${"0.0.1-SNAPSHOT".split("-")[0]}
|echo ${mvnProjectVersion.split(".".toRegex())[0]}
|echo ${arrayOfPackageVersion}
|echo ${arrayOfPackageVersion[0]}
|echo ${versionCheck("%maven.project.version%")}
""".trimMargin()
enabled = true
}
}
In this example there is only one case when i receive what I want, here it is:
echo ${"0.0.1-SNAPSHOT".split("-")[0]}
Here is my stdout from pipeline:
echo 0.0.1-SNAPSHOT
echo 0.0.1-SNAPSHOT
echo [0.0.1-SNAPSHOT]
echo 0.0.1-SNAPSHOT
echo 0.0.1
echo
echo [0.0.1-SNAPSHOT]
echo 0.0.1-SNAPSHOT
echo 0.0.1-SNAPSHOT
Please sign in to leave a comment.