将多个构建组合到一个发行版中 [英] Combine multiple builds into one release

查看:41
本文介绍了将多个构建组合到一个发行版中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在我们的CI/CD环境中使用VSTS.在我们的项目中,我们有多个部分,例如Database和Frontend1,它们在我们的存储库中有一个单独的文件夹:

We are using VSTS for our CI/CD environment. In our project we have multiple parts, like Database and Frontend1, which have a separate folder in our repository:

src/
   Database
   Frontend1
   ...

我为项目的每个组件创建了一个单独的构建,如果将更改推送到相应的子文件夹,则将触发这些构建.我希望这种分离可以轻松地控制和检查每个组件的版本.

I have created a separate build for each of the components of our project, which are triggered if there changes pushed to the corresponding subfolder. I want this separation to easily control and check the version of each component.

Database  --> Build Database
Frontend1 --> Build Frontend1

在这种配置下,如果我一次提交检入 Database Frontend1 的更改,就会触发两个构建.

With this configuration there are two builds triggered if I check in changes for Database and Frontend1 with a single commit.

此外,我已经配置了一个链接了两个工件的单个发行版.每次构建也会触发该版本.

Additionaly I have configured a single release with both artefacts linked. The release is also triggered for each build.

现在的问题是,如果我签入 Database Frontend1 的更改,则会触发两个构建,并且在每次构建后都会触发一个发布.这意味着我有两个发布用于同一提交.我要实现的是,只有一个结合了两个内部版本的发行版:

The problem now is, that if I check in a change for the Database and Frontend1, both builds are triggered and after every build there is also a release triggered. This means I have two releases for the same commit. I want to achive that there is only one release which combines both builds:

Database  --> Build Database   |
                               | --> Release Database and Frontend1
Frontend1 --> Builds Frontend1 |

是否有可能实现这种配置?

Is there any possibility to achive such a configuration?

推荐答案

最后,我找到了解决问题的方法.我创建了一个VSTS任务,如果没有其他正在运行/未排队的构建,则会在当前构建中添加标签:

Finally, I have found a solution for my problem. I have created a VSTS task which add a label to the current build if there is no other build running/queued:

[CmdletBinding()]
param(
    [string]    $teamfoundationCollectionUri = $env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI,
    [string]    $teamfoundationProject= $env:SYSTEM_TEAMPROJECT,
    [string]    $accessToken = "Bearer $env:SYSTEM_ACCESSTOKEN",
    [int]       $currentBuildId = $Env:BUILD_BUILDID,
    [string]    $tag
)

if(!$tag) 
{
    $tag = Get-VstsInput -Name "tag"
}

$buildInformationUrl = "$teamfoundationCollectionUri$teamfoundationProject/_apis/build/builds/$currentBuildId"

Write-Host "Loading build information: " $buildInformationUrl
$buildInformationResponse = Invoke-RestMethod -uri $buildInformationUrl -Headers @{Authorization = "$accessToken"}

$buildSourceVersion = $buildInformationResponse.sourceVersion

$openBuildsUrl = "$teamfoundationCollectionUri$teamfoundationProject/_apis/build/builds?statusFilter=inProgress,notStarted"

Write-Host "Requesting open builds: " $openBuildsUrl
$builds = Invoke-RestMethod -uri $openBuildsUrl -Headers @{Authorization = "$accessToken"}


$otherBuildForCommitIsRunning = $false
ForEach( $currentBuild in $builds.value ) 
{ 
    if($currentBuild.id -eq $currentBuildId) {

        Write-Host "Build with Id " $currentBuild.id " skipped"
        continue;
    }

    if($currentBuild.sourceVersion -eq $buildSourceVersion) {
        Write-Host "Found other open build: " $currentBuild.id

        $otherBuildForCommitIsRunning = $true
    }
}

if($otherBuildForCommitIsRunning -eq $false) {
    Write-Host "Tagging build with "$tag
    Write-Host "##vso[build.addbuildtag]$tag"
}

此外,我还为释放触发器添加了标签条件:

Additionally I have added a tag condition for the release trigger:

这篇关于将多个构建组合到一个发行版中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆