我在 azure 管道中有以下任務:
- task: PowerShell@2
displayName: Identiying the version fro the .csproj file
inputs:
targetType: "inline"
script: |
$xml = [Xml] (Get-Content ./src/MyProject/MyProject.csproj)
$version = $xml.Project.PropertyGroup.Version
echo $version
echo "##vso[task.setvariable variable=version]$version"
- task: PowerShell@2
displayName: Checking if the git tag with current version already
inputs:
targetType: "inline"
script: |
$ver=git tag -l $(version)
Write-Host "Project file version is $(version)"
Write-Host "Received from git tag $ver"
if ($(version) -eq $ver) {
Write-Error "Tag $(version) already exists"
}
else {
Write-Host "Tag does not exist"
}
它基本上從 csproj 檔案中提取版本,創建一個管道引數,然后呼叫git tag -l 以檢查該版本是否已作為標記存在。這里的問題是我們從 .csproj 檔案和 git 中提取的版本是相同的,但是 if 命令沒有被評估,而是執行 else。這是天藍色管道的輸出日志:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\e1cb6bb9-fbd4-4282-a4cc-e74f89ac7660.ps1'"
Project file version is 0.2.5
Received from git tag 0.2.5
Tag does not exist
為什么會發生這種情況,因為它們是平等的?結果應該是Tag 0.2.5 already exists
uj5u.com熱心網友回復:
如果 $(version) -eq $ver 為假,那么它們可能是不同的型別?嘗試手動轉換為字串:
if ("$(version)" -eq "$ver") {
關于您的評論-我對 az 管道不是很熟悉,但也許您可以像這樣轉換遠程變數?
[string]($(version))
型別也是物件,因此要將當前型別視為字串,請$var.GetType().name改用
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/466231.html
標籤:电源外壳 天蓝色的devops 天蓝色管道
