在TFS 2018中,我们可能会“在构建进行中批处理更改”,这样,如果在构建进行中进行Git推送,第二个将等待first to complete。这样,我们可以阻止多个构建同时运行。
但是,发行版似乎没有类似的选择。
鉴于我严格限制的带宽,完成一个给定的发行版所花费的时间可能比触发它的构建所花费的时间更长。即使正在进行中,第二个构建很有可能会触发一个新版本,即使已经在进行中。我需要将整个管道排队,直到当前版本完成为止,而不仅仅是构建。
我已经能够使用一系列笨拙的PowerShell脚本(要在当前状态下进行配置很繁琐)来做到这一点,但是如果可能的话,我希望有一些更坚实的方法。
我怎样才能最好地做到这一点?
Test-PipelineStatus.ps1
$BuildDefinitionName = (Get-Item Env:BUILD_DEFINITIONNAME).Value
$ArtifactsDirectory = (Get-Item Env:BUILD_ARTIFACTSTAGINGDIRECTORY).Value
$SourcesDirectory = (Get-Item Env:BUILD_SOURCESDIRECTORY).Value
$LocatorFilePath = "$ArtifactsDirectory\Locator.txt"
$StatusDirectory = "$SourcesDirectory\Pipeline"
$StatusFilePath = "$StatusDirectory\Status.txt"
Set-Content $LocatorFilePath $StatusFilePath
If ((Test-Path $StatusDirectory) -eq $False) {
Write-Output "Creating pipeline status directory"
New-Item $StatusDirectory -ItemType Directory
}
Write-Output "Getting current pipeline status"
If (Test-Path $StatusFilePath) {
$Status = Get-Content $StatusFilePath
If ($Status -eq "Stopped") {
Write-Output "Setting current pipeline status to [Running]"
Set-Content $StatusFilePath "Running"
} Else {
Write-Error "Pipeline [$BuildDefinitionName] is already in progress. Failing this build."
Exit 1
}
} Else {
Write-Output "Setting current pipeline status to [Running]"
Set-Content $StatusFilePath "Running"
}
Get-StatusFilePath.ps1
$ArtifactsDirectory = (Get-Item Env:SYSTEM_ARTIFACTSDIRECTORY).Value
$ReleaseDefinition = (Get-Item Env:RELEASE_DEFINITIONNAME).Value
$LocatorFilePath = "$ArtifactsDirectory\$ReleaseDefinition\drop\Locator.txt"
$StatusFilePath = Get-Content $LocatorFilePath
Write-Output "Setting variable [StatusFilePath] to [$StatusFilePath]"
Write-Host "##vso[task.setvariable variable=StatusFilePath]$StatusFilePath"
Remove-Item $LocatorFilePath
Set-ReleaseComplete.ps1
[CmdletBinding()]
param(
[Parameter(Mandatory)][string] $StatusFilePath
)
Write-Output "Marking pipeline as complete"
Set-Content $StatusFilePath -Value "Stopped"