简体   繁体   English

如何从 azure devops 中的另一个构建管道触发构建

[英]How to trigger a build from another build pipeline in azure devops

I have two build pipeline for two different projects.One is for building the actual project and another build pipeline for test automation.我有两个用于两个不同项目的构建管道。一个用于构建实际项目,另一个构建管道用于测试自动化。 I want to automatically trigger the build pipeline of test automation once the actual project build succeed.一旦实际项目构建成功,我想自动触发测试自动化的构建管道。

does there any possible way can i add one more task down to the actual build to trigger the test automation build, or suggest a possible way for the same.有什么可能的方法我可以在实际构建中添加一个任务来触发测试自动化构建,或者建议一种可能的方法。

在此处输入图像描述

Answers are much appreciable!!答案非常可观!!

You can use the "Build Completion" trigger in your second pipeline:您可以在第二个管道中使用“构建完成”触发器:

在此处输入图像描述

Additionally, you can add PowerShell script to queue another build from the parent build.此外,您可以添加 PowerShell 脚本以将来自父构建的另一个构建排队。 Example:例子:

$user = ""
$token = $env:SYSTEM_ACCESSTOKEN

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$orgUrl = "$env:SYSTEM_COLLECTIONURI"
$teamProject = "$env:SYSTEM_TEAMPROJECT"
$buildBodyTemplate = "{`"definition`": {`"id`": <build_id>}}"

$restApiQueueBuild = "$orgUrl/$teamProject/_apis/build/builds?api-version=6.0"

function InvokePostRequest ($PostUrl, $body)
{   
    return Invoke-RestMethod -Uri $PostUrl -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}  -Body $body
}

function RunBuild($buildId)
{
    $buildBody = $buildBodyTemplate.Replace("<build_id>", $buildId)            
    Write-Host $buildBody
    
    $buildresponse = InvokePostRequest $restApiQueueBuild $buildBody
    Write-Host $buildresponse
}

RunBuild SECOND_BUILD_ID

Update SECOND_BUILD_ID to ID of your build definition with tests.使用测试将SECOND_BUILD_ID更新为构建定义的 ID。 Additionally, add access to the security token in the parent build:此外,在父构建中添加对安全令牌的访问:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure DevOps - 管道不应触发 PR 构建 - Azure DevOps - Pipeline should not trigger build for PR 如何根据提交消息触发 azure devops build pipeline? - How to trigger azure devops build pipeline based on the commit message? 从另一个管道触发 Azure DevOps 管道 - Trigger Azure DevOps pipeline from another pipeline 如何从 Azure DevOps 中的另一个管道触发一个管道阶段? - How to trigger one pipeline stage from another pipeline in Azure DevOps? 从 azure devops 构建成功后如何使用脚本或管道触发拉取请求 - How to Trigger a pull request using script or pipeline once build is successful from azure devops Azure DevOps:如何从 Release Pipeline 中的 PowerShell 脚本构建 Azure Pipeline 检索构建工件? - Azure DevOps: How to retrieve a build artifact from build Azure Pipeline from a PowerShell Script in Release Pipeline? 在 Azure Devops 的项目中触发另一个构建 - Trigger another build exist in project in Azure Devops 如何在 Azure DevOps 管道中管理构建工件? - How build artifacts are managed in Azure DevOps pipeline? 如何区分 azure DevOps 构建管道中的分支触发器和计划触发器 - How to differentiate between branch trigger and the scheduled trigger in azure DevOps build pipeline Azure devops:在不同存储库的分支上构建管道触发器 CI - Azure devops: Pipeline Trigger CI build on branch in different repositories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM