I would like to activate a specific set of tools via SDKMAN in my scripted Jenkinsfile pipeline.
Basically I would like to do
node("sdkman && mvn386") {
sh "sdk use maven 3.8.6"
sh "sdk current" // << back to whatever was before
sh "mvn --version"
sh "mvn clean install"
}
But since sdk ... is executed in a subshell the use is not active in the next like.
(It would work with sdk default ... but that is out of the question, because I do not want to destroy other running pipelines)
Semantically it would be something like this I need (which is not supported, I think):
node("sdkman && mvn386") {
sh ("sdk use maven 3.8.6") { // << unsupported syntax
sh "sdk current"
sh "mvn --version"
sh "mvn clean install"
}
}
How can I keep the changes that sdk makes to the shell env to the next lines? Is there another tool to use instead of sh? Something like withEnv?
Side problem: Because sdk is just a shell function I needed to create a wrapper script sdh.sh (containing sdk $*). That of course defies the "chaning the environment", too. sh "sdk ..." just does not seem to work with shell functions. Any way around that?
Something I do not want to do is putting the script lines into one block, because that would not work well with our more complicated pipelines.
sh '''
sdk use maven 3.8.6
sdk current
''' // << I dont want to do this in one shell block