目前 yaml 管道不支持手动部署到阶段。请检查这个开放问题.
您可以尝试添加依赖于取决于 and 状况每个阶段。对于下面的示例 yaml 管道。阶段Build仅在阶段结束后才开始运行Start成功完成后,阶段构建将等待批准,只有阶段构建获得批准并成功完成后,才会触发阶段发布。
您可以定义公关触发并设置autocancel=true
(默认为 true)如果新更改被推送到同一个 pr,则取消先前的运行。
The batch财产为trigger
可以达到类似的效果。如果当前 pr 仍在构建中,则不会启动新的运行。
trigger:
batch: boolean # batch changes if true (the default); start a new build for every push if false
branches:
include:
_
pr:
autoCancel: true
branches:
include:
- master
stages:
- stage: Start
jobs:
- job: A
pool:
vmImage: windows-latest
steps:
- powershell: |
echo "i am job a"
- stage: Build
dependsOn: Start
condition: succeeded()
jobs:
- deployment: Dev
displayName: deploy Web App
pool:
vmImage: 'Ubuntu-16.04'
# creates an environment if it doesn't exist
environment: 'Dev'
strategy:
# default deployment strategy, more coming...
runOnce:
deploy:
steps:
- script: echo "i am dev environment"
- stage: Release
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Environ
displayName: deploy Web App
pool:
vmImage: 'Ubuntu-16.04'
# creates an environment if it doesn't exist
environment: 'Environment'
strategy:
# default deployment strategy, more coming...
runOnce:
deploy:
steps:
- script: echo "i am Environment environment"
Update: 通过 powershell 脚本取消正在进行的构建.
您可以在管道顶部添加一个 powershell 任务来调用构建API。下面的脚本获取所有正在进行的构建并取消它们(当前构建除外)。
- task: PowerShell@2
inputs:
targetType: inline
script: |
$header = @{ Authorization = "Bearer $(system.accesstoken)" }
$buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=5.1"
echo $buildsUrl
$builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
$buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -ne $(Build.BuildId))})
ForEach($build in $buildsToStop)
{
echo $build.id
$build.status = "cancelling"
$body = $build | ConvertTo-Json -Depth 10
$urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=5.1"
echo $urlToCancel
Invoke-RestMethod -Uri $urlToCancel -Method Patch -ContentType application/json -Body $body -Header $header
}
为了让您的管道有权取消当前正在运行的构建。您需要转到管道,单击 3dots 并选择管理安全性
![enter image description here](https://i.stack.imgur.com/3JvrV.png)
然后设置停止构建s 允许用户的权限项目集合构建服务(projectName),
![enter image description here](https://i.stack.imgur.com/lUPWa.png)