简体   繁体   中英

Password with special character in the scripted Jenkins pipeline for 7z command

I am working on a scripted Jenkins pipeline. I have stored a secret in Credential plugin. I want to use that secret when creating an achieve using 7z. Here is my code:

stage('Zip and Encrypt Artifacts') {
   withCredentials([string(credentialsId: 'encryption_key', variable: 'SHARED_PASSWORD')]) {
      archive = report.replace(".txt",".7z")
      sh "7z a -p${SHARED_PASSWORD} -mhe ${archive} ${report}"
      sh "rm ${report}"
   }

}

This code works with simple password. But, it fails with strong password. What is your suggestion? How should I change the sh command?

thanks.

Quote all your variables:

    sh '''
        7z a "-p${SHARED_PASSWORD}" -mhe "${archive}" "${report}"
        rm "${report}"
    '''

Note that you need to use single quotes around the script so you can use double quotes inside it. You have to use double quotes in the shell command so that variables will be expanded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM