用管道资源手动触发DevOps管道应使用该分支的最新资源管道运行

发布于 2025-02-01 19:25:24 字数 398 浏览 5 评论 0原文

我在相同的存储库中有2个管道:

  1. 构建
  2. 部署

构建管道被声明为部署管道中的管道资源:

resources:
  pipelines:
  - pipeline: Build 
    source: BuildPipelineName
    trigger: true

当我运行构建管道时,在同一分支上正确触发了部署管道。但是,当我手动运行部署管道时,它不会使用同一分支运行的最新管道。

我尝试将下面的几行变体添加到管道资源中,但是变量没有扩展:

branch: ${{ variables.Build.SourceBranchName }}

有什么方法可以使此工作?

I have 2 pipelines in the same repo:

  1. Build
  2. Deploy

The Build pipeline is declared as a pipeline resource in the Deploy pipeline:

resources:
  pipelines:
  - pipeline: Build 
    source: BuildPipelineName
    trigger: true

When I run the Build pipeline, the Deploy pipeline is correctly triggered on the same branch. However, when I run the Deploy pipeline manually, it does not use the latest pipeline run from same branch.

I tried adding a couple of variations of the line below to the to the pipeline resource, but the variable does not expand:

branch: ${{ variables.Build.SourceBranchName }}

Is there any way to make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

著墨染雨君画夕 2025-02-08 19:25:24

解决方法可以实现我想要的结果,但不是很优雅:

          - ${{ if ne(variables['Build.Reason'], 'ResourceTrigger')  }}:
            - task: DeleteFiles@1
              displayName: 'Remove downloaded artifacts from pipeline resource'
              inputs:
                SourceFolder: $(Pipeline.Workspace)

            - task: DownloadPipelineArtifact@2
              displayName: 'Download artifacts for branch'
              inputs:
                source: 'specific'
                project: 'myProject'
                pipeline: <BuildPipelineId>
                runVersion: 'latestFromBranch'    
                runBranch: $(Build.SourceBranch)

Workaround that achieves the result I am looking for, but is not very elegant:

          - ${{ if ne(variables['Build.Reason'], 'ResourceTrigger')  }}:
            - task: DeleteFiles@1
              displayName: 'Remove downloaded artifacts from pipeline resource'
              inputs:
                SourceFolder: $(Pipeline.Workspace)

            - task: DownloadPipelineArtifact@2
              displayName: 'Download artifacts for branch'
              inputs:
                source: 'specific'
                project: 'myProject'
                pipeline: <BuildPipelineId>
                runVersion: 'latestFromBranch'    
                runBranch: $(Build.SourceBranch)
他是夢罘是命 2025-02-08 19:25:24

这对我有用:

resources:
  pipelines:
  - pipeline: buildpipelineCI 
    source: 'Other pipeline-CI' 
    trigger: true
    branch: ${{variables['Build.SourceBranch']}}

This works for me:

resources:
  pipelines:
  - pipeline: buildpipelineCI 
    source: 'Other pipeline-CI' 
    trigger: true
    branch: ${{variables['Build.SourceBranch']}}
茶底世界 2025-02-08 19:25:24

例如,如果我有一个名为“ build Pipileaneanddeploypipeline”的构建管道,

那么以下YAML定义可以从特定分支机构中运行最新的构建管道:

resources:
  pipelines:
  - pipeline: BuildPipelineAndDeployPipeline
    project: xxx
    source: BuildPipelineAndDeployPipeline
    trigger:
      branches:
      - main

pool:
  vmImage: 'windows-latest'


steps:
- task: CmdLine@2
  inputs:
    script: |
      echo Write your commands here
      
      echo Hello world
      
      echo $(resources.pipeline.BuildPipelineAndDeployPipeline.runID)

For example, if I have a build pipeline named 'BuildPipelineAndDeployPipeline',

then the below YAML definition can get the latest build pipeline run from a specific branch:

resources:
  pipelines:
  - pipeline: BuildPipelineAndDeployPipeline
    project: xxx
    source: BuildPipelineAndDeployPipeline
    trigger:
      branches:
      - main

pool:
  vmImage: 'windows-latest'


steps:
- task: CmdLine@2
  inputs:
    script: |
      echo Write your commands here
      
      echo Hello world
      
      echo $(resources.pipeline.BuildPipelineAndDeployPipeline.runID)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文