I have a pipeline script using a git URL with whitespaces https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core - Stream
:
node ("master") {
bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%20-%20Stream", encoding: "UTF-8" ])
}
When this jenkins job is executed, it fails because '%20'
is replaced with '0'
. Log saying that:
git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core0-0Stream
remote: TF401019: The Git repository with name or identifier Core0-0Stream does not exist or you do not have permissions for the operation you are attempting.
fatal: repository 'https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core0-0Stream/' not found
How to encode git url properly using bat task in jenkins pipeline script
Your %20
character is most probably interpreted as a variable. You have a lot of solutions :
Remove interpolation from your bat script. For that, use simple quotes
instead of double quotes
:
bat([script: 'git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%20-%20Stream', encoding: "UTF-8" ])
Plus sign should not be interpreted as a variable and should be valid as a space in URL :
bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core+-+Stream", encoding: "UTF-8" ])
I didn't test it but most probably with your bat script it's the %
that gets interpreted and replaced. To avoid that you could try to escape it with a %%
:
bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%%20-%%20Stream", encoding: "UTF-8" ])
Note : According to this article , %
character must be escaped with another percent char, so : %%
.
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.