I am using below code in CASE 1 in my jenkins library , it is able to render the artifactory password and username inside the sh block but not able to render the variable docker_repo , if I replace it with code in CASE 2 it works fine but it is an unsafe practice , Any idea why it is happening ? and how to overcome it ?
CASE 1
def dockerAuth(String creds = 'mysecret',String docker_repo = ARTF_URL) {
withCredentials([usernamePassword(credentialsId: creds,
usernameVariable: 'ARTIFACTORY_USER',
passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
//opts = '-u $ARTIFACTORY_USER -p $ARTIFACTORY_PASSWORD'
sh 'sudo docker login -u $ARTIFACTORY_USER -p $ARTIFACTORY_PASSWORD $docker_repo'
}
}
CASE 2
def dockerAuth(String creds = 'mysecret',String docker_repo = ARTF_URL) {
withCredentials([usernamePassword(credentialsId: creds,
usernameVariable: 'ARTIFACTORY_USER',
passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
//opts = '-u $ARTIFACTORY_USER -p $ARTIFACTORY_PASSWORD'
sh "sudo docker login -u ${ARTIFACTORY_USER} -p ${ARTIFACTORY_PASSWORD} ${docker_repo}"
}
}