Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
避免在使用';git推送';从另一条管道_Git_Azure Devops_Azure Pipelines - Fatal编程技术网

避免在使用';git推送';从另一条管道

避免在使用';git推送';从另一条管道,git,azure-devops,azure-pipelines,Git,Azure Devops,Azure Pipelines,我有一个主分支,在其管道中有一个powershell脚本,用于在流程结束时更新另一个分支(用于自动同步): # User and email must be set, otherwise an error occurs Write-Host "1: Set git configs" git config --global user.email "${env:BUILD_REQUESTEDFOREMAIL}" git config --global user.name "${env:BUILD_

我有一个主分支,在其管道中有一个powershell脚本,用于在流程结束时更新另一个分支(用于自动同步):

# User and email must be set, otherwise an error occurs
Write-Host "1: Set git configs"
git config --global user.email "${env:BUILD_REQUESTEDFOREMAIL}" 
git config --global user.name "${env:BUILD_REQUESTEDFOR}"

git checkout stage
git merge master
git push
如果我手动按下stage分支,通常会触发该分支的另一条管道。但是在这种情况下(当另一个管道推送时),我不想触发,因为更改只涉及更改文档文件,并且没有必要浪费时间和资源来触发新构建

我的第一种方法是设置路径过滤器,以便在文件修改为CHANGELOG.md(文档文件)时排除

当我从我的计算机中推送时,它工作,但当推送来自构建代理计算机时,它不工作(它仍在触发)

我怎样才能避免触发?另一种方法也值得欢迎

提前感谢

查看“当脚本推送时,如何避免触发CI生成?”的文档,如下所示:


Git merge apply不会创建新提交。您可以在命令行结果中找到
(未创建提交;-m选项被忽略)

git merge -m "[skip ci] Merge from build agent" branch
Updating ed7d8f5..11d4c44
Fast-forward (no commit created; -m option ignored)
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
您可以使用
--no ff
选项避免快进并使用[skip ci]消息创建提交:

git merge --no-ff -m "[skip ci] Merge from build agent" branch
Merge made by the 'recursive' strategy.
 README.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
另一种方法(但可能更复杂)是使用Pull请求创建带有[skip ci]消息的提交。下面是要在生成代理上运行的power shell示例:

$user = ""
$token = "$(System.AccessToken)"
$branchTarget = "refs/heads/stage"
$branchSource = "refs/heads/master"
$teamProject = "$(System.TeamProject)"
$repoName = "$(Build.Repository.Name)"
$orgUrl = "$(System.CollectionUri)"

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

$uriCreatePR = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/pullrequests?api-version=5.1"
$uriUpdatePR = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/pullrequests/{pullRequestId}?api-version=5.1"

$bodyCreatePR = "{sourceRefName:'$branchSource',targetRefName:'$branchTarget',title:'Sync changes from $branchSource [skip ci]'}"
$bodyUpdatePR = "{status:'completed',lastMergeSourceCommit:{commitId:'{commitId}',url:'{url}'}}"

$resultNewPR = Invoke-RestMethod -Uri $uriCreatePR -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $bodyCreatePR

Write-Host "Created PR" $resultNewPR.pullRequestId

$uriUpdatePR = $uriUpdatePR -replace "{pullRequestId}", $resultNewPR.pullRequestId
$bodyUpdatePR = $bodyUpdatePR -replace "{commitId}", $resultNewPR.lastMergeSourceCommit.commitId
$bodyUpdatePR = $bodyUpdatePR -replace "{url}", $resultNewPR.lastMergeSourceCommit.url

$resultUpdatedPR = Invoke-RestMethod -Uri $uriUpdatePR -Method Patch -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $bodyUpdatePR

Write-Host "Completed PR" $resultUpdatedPR.pullRequestId

不确定它是否会工作(因为不是所有推送的提交都会有),但您可以尝试通过添加
[skip ci]
(请参阅)@Philippe我已经尝试过了…不知怎的,当推送来自另一个管道(azure devops内部)时,它只是忽略了这些规则…@daniluziska Yes,如果您的合并没有冲突,它将忽略。--没有ff做了这个把戏…只是另一个注意事项…在另一个更改文档并推送到主控的脚本中,我已经添加了[ci skip](以避免在无限循环中触发主控管道),尽管在我合并到阶段时会执行此提交,当我推到stage时,它不被识别,所以我必须按照您的建议使用[ci skip]创建另一个提交。谢谢