手动发布,用户选择构建ID。
手动发布,用户没有选择任何特定的构建,以便选择最新的构建。trigger:
- none
schedules:
- cron: '*/5 * * * *' # Runs every 5 minutes for testing, otherwise runs every 24 hours
displayName: Daily midnight build
branches:
include:
- feature/ps/schedule_change
always: true
pool:
vmImage: 'ubuntu-latest'
variables:
buildTag: ''
steps:
- script: |
date=$(date +%Y%m%d)
tag="scheduled-build-$date-$(Build.BuildId)"
echo "##vso[build.addbuildtag]$tag"
echo "##vso[task.setvariable variable=buildTag]$tag"
displayName: 'Tag build with date and ID'
release管道
trigger: none
variables:
- name: isScheduledRelease
value: false
- name: buildTag
value: ''
- name: selectedBuildId
value: ''
resources:
pipelines:
- pipeline: apipipeline
source: Build-API
trigger:
branches:
include:
- develop
schedules:
- cron: "0 11 * * *"
displayName: Daily
branches:
include:
- develop
- main
- feature/ps/schedule_change
always: true
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: ScheduleChange
displayName: sample
condition: or(eq(variables['Build.Reason'], 'Schedule'), eq(variables['Build.Reason'], 'Manual'))
dependsOn:
jobs:
- deployment: api
condition:
displayName: API Deployment
environment: 'Sample'
variables:
- group: Sample
strategy:
runOnce:
deploy:
steps:
- download: none
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
if ($env:BUILD_REASON -eq "Schedule") {
Write-Host "inside schedule"
$date = Get-Date -Format "yyyyMMdd"
$tag = "scheduled-build-api-$date"
Write-Host "##vso[task.setvariable variable=buildTag;isOutput=true]$tag"
Write-Host "##vso[task.setvariable variable=isScheduledRelease;isOutput=true]true"
Write-Host "build tag is $tag"
Write-Host "build reason schedule"
} else ($env:BUILD_REASON -eq "Manual" -and $env:BUILD_BUILDID) {
Write-Host "##vso[task.setvariable variable=selectedBuildId;isOutput=true]$env:BUILD_BUILDID"
Write-Host "##vso[task.setvariable variable=isScheduledRelease;isOutput=true]false"
Write-Host "build tag is $env:BUILD_BUILDID"
Write-Host "build reason manual with build id"
}
displayName: 'Check if release is scheduled'
- checkout: self
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
if ($env:buildTag -eq '') {
$latestBuild = (Invoke-RestMethod -Uri "https://dev.azure.com/Org/Proj/_apis/build/builds?definitions=defId&\$top=1&api-version=6.0" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}).value[0].id
Write-Host "##vso[task.setvariable variable=latestBuildId;isOutput=true]$latestBuild"
Write-Host "latest build is $latestBuild"
}
displayName: 'Get Latest Build ID'
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'specific'
project: 'proj'
pipeline: 'pipelineid'
runVersion: 'specific'
runId: '123412' #${{ coalesce(variables['buildTag'], variables['selectedBuildId'], variables['latestBuildId']) }}
targetPath: '$(Pipeline.Workspace)/apipipeline'
由于计划发行版采用最新版本,因此发生了什么,假设它来自计划的构建和部署。但是,有时可能不是这种情况,最新的构建可能来自不同的分支机构,最终使用错误的构建进行了部署。基于您的描述,我的理解是,您的发布正在从计划的构建中消耗工件。如果是这样,为什么不在您的版本中添加计划的构建作为管道资源呢?
resources:
pipelines:
- pipeline: BuildPipeline
source: BuildPipeline
trigger:
branches:
include:
- {include all your target branches}
steps:
- download: BuildPipeline
当发行版手动触发时,您可以手动选择特定的构建版本或使用默认的最新版本。单击运行管道 - >资源 - >选择您的构建管道 - >使用选定的运行。