如何设置azure devops发布同步管道,以便每当发生冲突时都会抛出冲突消息失败

问题描述 投票:0回答:1

我创建了一个同步管道

添加了一个 PowerShell 任务,因为有两个分支,所以基本上每当任何更改合并到主分支时,我都会尝试将其同步到我的功能分支中。将以下代码添加到 power shell 中。

git config --global user.email $(EmailAddress)

git status

git fetch "https://$(UserName):$(PAT)@dev.azure.com/gpb/g%20p%20b%20c/_git/gpb_c"

git checkout feature/pal/branchdev2

git pull origin feature/pal/branchdev2

git status

git checkout feature/pal/branchdev1

git pull origin feature/pal/branchdev1

git merge feature/pal/branchdev2

git status

git add .

git commit -m "push"

git push origin feature/pal/branchdev1

所以在这里我们可以说 feature/pal/branchdev2 这是我的主分支,所以我将从中提取新的更改并尝试将两个合并到功能分支“feature/pal/branchdev1”

因此,每当两个分支之间发生冲突时,我的管道就会因错误而失败

##[error]PowerShell exited with code '1'.

还添加了屏幕截图在此处输入图像描述

在日志中得到

CONFLICT (content): Merge conflict in README.md

所以我不会设置,每当两个分支之间发生冲突时,我的管道就会因错误冲突而失败。

我尝试了 PowerShell 任务中的一些设置选项 在此处输入图像描述

但无法使用指定选项抛出错误。请建议一个选项,以便管道因冲突错误而失败。

azure-devops azure-powershell
1个回答
0
投票

但无法使用指定选项抛出错误。请建议一个选项,以便管道因冲突错误而失败。

您可以重定向合并错误,并检查合并退出代码,如果它不为零(发生冲突),请使用logging命令

Write-Host "##vso[task.logissue type=error]conflict error"
显示冲突详细信息。

详情如下:

# Attempt to merge and check if there is a conflict, redirect the message
git merge feature/pal/branchdev2 >> log

# If there is a conflict, the merge command will return a non-zero status, output the message on the log, and exit.
if ($LASTEXITCODE -ne 0) {
    Write-Host "##vso[task.logissue type=error]$(cat log)"
exit 1
}

enter image description here

无需使用任务设置,详情如下:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.