我有一个使用git URL的管道脚本,其中包含空格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" ])
}
当执行此jenkins作业时,它会失败,因为'%20'
已替换为'0'
。记录说:
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
如何使用jenkins管道脚本中的bat task正确编码git url
答案 0 :(得分:1)
您的%20
字符很可能被解释为变量。你有很多解决方案:
从bat脚本中删除插值。为此,请使用simple quotes
代替double quotes
:
bat([script: 'git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%20-%20Stream', encoding: "UTF-8" ])
加号不应被解释为变量,并且应该在URL中作为空格有效:
bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core+-+Stream", encoding: "UTF-8" ])
我没有测试它,但很可能是你的蝙蝠脚本,它是被解释和替换的%
。为避免这种情况,您可以尝试使用%%
:
bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%%20-%%20Stream", encoding: "UTF-8" ])
注意:根据this article,%
字符必须使用另一个百分比字符进行转义,因此:%%
。