![](/img/trans.png)
[英]Escape special character of git password in Jenkins pipeline groovy script
[英]Jenkins Pipeline Groovy script: batch script issue '%20' is replaced with '0'
我有一個使用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" ])
}
當執行此詹金斯作業時,它失敗,因為'%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
如何在詹金斯管道腳本中使用bat任務正確編碼git url
您的%20
字符很可能被解釋為變量。 您有很多解決方案:
從蝙蝠腳本中刪除插值。 為此,請使用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腳本一起使用的,它是%
會被解釋和替換。 為了避免這種情況,您可以嘗試使用%%
對其進行轉義:
bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%%20-%%20Stream", encoding: "UTF-8" ])
注意:根據本文 , %
字符必須使用另一個%char進行轉義,因此: %%
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.