在编写 Jenkinsfile 时经常会使用到 credentials
现象
最近在工作中遇到一个坑,就是在使用 Username and password 类型的 credentials 时,如果 password 中带有 $ 则 Jenkins 会自动转换。比如:$# 会变成 0。
实际场景:
sshpass -p ${CREDS_PSW} ssh -o "StrictHostKeyChecking no" ${CREDS_USR}@${SERVER} mkdir -p ${BASE_PATH}${PROJECT_PATH}
解决办法
将 sshpass -p '65$#@!' 中 '65$#@!' 一起设置为 credentials 中的 password。也就是说把单引号也包括在内,这样 Jenkins 就不会进行奇怪的转换了。
缺点
Jenkins credentials 中的 password 中包括了不必须的单引号。如果有其他地方需要原始的密码,还是有这个问题。希望有明白的大神,可以留言解决办法。