Since pretty recently, Jenkins prints out warnings when one inserts e.g. credentials into the 'script' arg of the sh command, and the warnings referring to this help page:
Me being curious I am trying to get rid of those warnings but failing no matter what I try.
Here is the relevant section of our scripted pipeline file:
withCredentials([usernamePassword(credentialsId: 'credentialsGenerateFromDb',
usernameVariable: 'GEN_USR',
passwordVariable: 'GEN_PASSWD')]) {
String m2RepoIdentifier = "${env.BRANCH_NAME}_${env.BUILD_NUMBER}"
withEnv(javaAndMavenEnvArray()) {
sh '${JAVA_HOME}/bin/java -version'
sh "${mvnCommand(m2RepoIdentifier)} -f project-reactor/pom.xml" +
" -P GenerateProfile -DdeployAtEnd=true" +
" '-Dproj.build.generatefromdb.url=${jdbcUrlNoData()}'" +
" '-Dproj.build.generatefromdb.user=${env.GEN_USR}'" +
" '-Dproj.build.generatefromdb.password=${env.GEN_PASSWD}'" +
" clean ${mvnBuildGoal} pmd:pmd pmd:cpd"
}
}
Where both mvnCommand(String) and jdbcUrlNoData() are functions defined in a shared library.
I have tried to use single quotes (which obviously works in some cases, see the first sh command in my example above), and multi-line strings using single quotes and double quotes.
But either the variables do not get interpolated, or I dont get rid of the warnings.
So what is the recommended way of building up an sh command that contains both dynamic values from functions and credentials that should not be left to groovy to be interpolated? The more I google around the more complicated this gets (and the more different "solutions" I find, including e.g. wrapping the ${SOME_VAR} with double quotes inside a single-quoted string).
Would really appreciate if someone could shed some light on this problem, thanks!
stefan.