
我想採用這個 buildVariable
Build.SourceVersion
例如,這等於:
0gc58d92d905d62415b8866g3f48f17416da426s
並將從數字 [7] 到行尾替換為空字串
0gc58d92
我試過
- ShortCommitId: ${{ replace(variables['Build.SourceVersion'], '[[8]-$]','') }}
但沒用
答案1
這子字串()方法將從中獲取字串值Build.SourceVersion
,並且可以傳遞兩個int
參數。一個將輸出從特定字元位置開始的字串值,另一個告訴它要輸出的後續字元位置。
$a = "0gc58d92d905d62415b8866g3f48f17416da426s"
$a.substring(0,7)
輸出
0gc58d9
透過子字串()方法只有一個int
參數告訴它起始字元位置,以便僅輸出所有後續字符位置字符,直到字串末尾。
$a = "0gc58d92d905d62415b8866g3f48f17416da426s"
$a.substring(8)
輸出
d905d62415b8866g3f48f17416da426s
支持資源
-
Substring(Int32)
- 從此實例中檢索子字串。子字串從指定字元位置開始,一直到字串末尾。
Substring(Int32, Int32)
- 從此實例中檢索子字串。子字串從指定的字元位置開始並具有指定的長度。