如何在Azure Devops中的单独的YML管道中处理计划的构建和预定释放。

问题描述 投票:0回答:1
Handle计划发布,应选择计划的构建。

手动发布,用户选择构建ID。

手动发布,用户没有选择任何特定的构建,以便选择最新的构建。
  1. 目前,我能够标记构建。但是在发行期间,默认情况下下载最新的工件并开始使用,除非我们手动选择构建ID。但是,我将下载添加为false,但它仍然使用最新的构建。我尝试在您在下面看到的版本中进行硬编码,它下载了工件,但不像它一样使用它们,只能使用最新。我正在添加构建并释放yaml。
  2. 是我的方法吗?还有其他更好的方法来满足要求吗?
  3. 建造管道
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

您可以将所有提到的分支添加为“最新构建可能来自不同分支”作为分支触发过滤器。
当发行版手动触发时,您可以手动选择特定的构建版本或使用默认的最新版本。单击运行管道 - >资源 - >选择您的构建管道 - >使用选定的运行。
azure azure-devops azure-pipelines devops azure-pipelines-yaml
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.