在TFS 2018中,我们可以“在生成过程中进行批处理更改”,以便如果在生成过程中发生Git推送,则第二个将等待
first to complete
是的。这样,我们就可以阻止多个生成同时运行。
然而,对于发行版,似乎没有类似的选择。
鉴于我的带宽非常有限,一个给定的版本可能需要比触发它的构建更长的时间才能完成。很有可能,第二个构建,即使是排队的时候,也会触发一个正在进行的新版本。我需要将整个管道排队,直到当前版本完成,而不仅仅是生成。
我可以用一系列笨拙而脆弱的powershell脚本(在当前状态下配置起来很乏味)来完成这项工作,但如果可能的话,我希望有一些更可靠的脚本。
我怎样才能做到最好?
测试管线状态.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"
}
获取-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
整套释放装置.ps1
[CmdletBinding()]
param(
[Parameter(Mandatory)][string] $StatusFilePath
)
Write-Output "Marking pipeline as complete"
Set-Content $StatusFilePath -Value "Stopped"