Trying to make pipeline more flexible

In general, I have one pipeline (SourcePipeline) which triggers the another one (DependantPipeline), and two of them are in specific repository devops-med. Also, two of them are using pipeline definitions from other repository global-pipelines.

My set of pipelines works as expected, however they need some adjustment not to use the hardcoded names in some pipelines definitions. I am using the hardcoded name of the repository to which pipeline is attached to.

Pipelines definitions in devops-med repository based on my already working approach:

devops-med/devops/pipeline.yml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>name: $(Build.DefinitionName) # added new line on 08/31
name: SourcePipeline # removed that line on 08/31
resources:
repositories:
- repository: global-pipelines
type: git
name: global-pipelines
ref: test/pipeline
trigger:
batch: true
branches:
include:
- test/pipeline
pr: none
parameters:
- name: pipelineMode
displayName: Pipeline Mode
type: string
default: main
values:
- auto
- feature
- main
extends:
template: /cicdTemplates/pipeline.yml@global-pipelines
parameters:
variablesTemplate: devops/variables/global_variables.yml@self
pipelineMode: ${{parameters.pipelineMode}}
buildJobs: devops/build_jobs.yml@self
</code>
<code>name: $(Build.DefinitionName) # added new line on 08/31 name: SourcePipeline # removed that line on 08/31 resources: repositories: - repository: global-pipelines type: git name: global-pipelines ref: test/pipeline trigger: batch: true branches: include: - test/pipeline pr: none parameters: - name: pipelineMode displayName: Pipeline Mode type: string default: main values: - auto - feature - main extends: template: /cicdTemplates/pipeline.yml@global-pipelines parameters: variablesTemplate: devops/variables/global_variables.yml@self pipelineMode: ${{parameters.pipelineMode}} buildJobs: devops/build_jobs.yml@self </code>
name: $(Build.DefinitionName) # added new line on 08/31
name: SourcePipeline  # removed that line on 08/31

resources:
  repositories:
    - repository: global-pipelines
      type: git
      name: global-pipelines
      ref: test/pipeline

trigger:
  batch: true
  branches:
    include:
      - test/pipeline

pr: none

parameters:
  - name: pipelineMode
    displayName: Pipeline Mode
    type: string
    default: main
    values:
      - auto
      - feature
      - main
    
extends:
  template: /cicdTemplates/pipeline.yml@global-pipelines
  parameters:
    variablesTemplate: devops/variables/global_variables.yml@self
    pipelineMode: ${{parameters.pipelineMode}}
    buildJobs: devops/build_jobs.yml@self

To that one I added in first line name: $(Build.DefinitionName), and removed name: SourcePipeline. Still works.

devops-med/devops/dependantpipeline.yml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>trigger: none
resources:
repositories:
- repository: global-pipelines
type: git
name: global-pipelines
ref: test/pipeline
pipelines:
- pipeline: SourcePipeline
project: DEV
# source: 'devops-med'
source: $(Build.DefinitionName) # added new line on 08/31
trigger:
branches:
include:
- test/pipeline
parameters:
- name: pipelineMode
displayName: Pipeline Mode
type: string
default: main
values:
- auto
- feature
- main
extends:
template: /cicdTemplates/pipeline.yml@global-pipelines
parameters:
variablesTemplate: devops/variables/global_variables.yml@self
pipelineMode: ${{parameters.pipelineMode}}
devEnvironment: dev
devVariables: devops/ew/variables/dev_variables.yml@self
deployEnvironmentTemplate: devops/deploy_environment.yml@self
</code>
<code>trigger: none resources: repositories: - repository: global-pipelines type: git name: global-pipelines ref: test/pipeline pipelines: - pipeline: SourcePipeline project: DEV # source: 'devops-med' source: $(Build.DefinitionName) # added new line on 08/31 trigger: branches: include: - test/pipeline parameters: - name: pipelineMode displayName: Pipeline Mode type: string default: main values: - auto - feature - main extends: template: /cicdTemplates/pipeline.yml@global-pipelines parameters: variablesTemplate: devops/variables/global_variables.yml@self pipelineMode: ${{parameters.pipelineMode}} devEnvironment: dev devVariables: devops/ew/variables/dev_variables.yml@self deployEnvironmentTemplate: devops/deploy_environment.yml@self </code>
trigger: none

resources:
  repositories:
    - repository: global-pipelines
      type: git
      name: global-pipelines
      ref: test/pipeline
  pipelines:
    - pipeline: SourcePipeline
      project: DEV
      # source: 'devops-med'
      source: $(Build.DefinitionName) # added new line on 08/31
      trigger:
        branches:
          include:
            - test/pipeline

parameters:
  - name: pipelineMode
    displayName: Pipeline Mode
    type: string
    default: main
    values:
      - auto
      - feature
      - main

extends:
  template: /cicdTemplates/pipeline.yml@global-pipelines
  parameters:
    variablesTemplate: devops/variables/global_variables.yml@self
    pipelineMode: ${{parameters.pipelineMode}}
    devEnvironment: dev
    devVariables: devops/ew/variables/dev_variables.yml@self
    deployEnvironmentTemplate: devops/deploy_environment.yml@self

In that one I changed source: 'devops-med' to source: $(Build.DefinitionName) as described in above pipeline definition. It does not work, I am getting the error in Azure DevOps:

/devops/dependantpipeline.yml (Line: 12, Col: 17): Pipeline Resource
SourcePipeline Input Must be Valid.

Maybe I am wrong with my assumption and can’t use Build.DefinitionName on dependantpipeline.yml and it must be hardcoded to know which excatly pipeline triggered it. However, I tried based on the documentation: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml

In general, the goal is not to use the hardcoded name devops-med.

EDIT 1.

When I did it in this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> parameters:
- name: sourcePipelineName
type: string
default: 'devops-med'
resources:
pipelines:
- pipeline: SourcePipeline
project: DEV
source: ${{ parameters.sourcePipelineName }}
trigger:
branches:
include:
- test/pipeline
extends:
template: /cicdTemplates/pipeline.yml@global-pipelines
parameters:
variablesTemplate: devops/variables/global_variables.yml@self
pipelineMode: ${{parameters.pipelineMode}}
devEnvironment: dev
devVariables: devops/ew/variables/dev_variables.yml@self
deployEnvironmentTemplate: devops/deploy_environment.yml@self
</code>
<code> parameters: - name: sourcePipelineName type: string default: 'devops-med' resources: pipelines: - pipeline: SourcePipeline project: DEV source: ${{ parameters.sourcePipelineName }} trigger: branches: include: - test/pipeline extends: template: /cicdTemplates/pipeline.yml@global-pipelines parameters: variablesTemplate: devops/variables/global_variables.yml@self pipelineMode: ${{parameters.pipelineMode}} devEnvironment: dev devVariables: devops/ew/variables/dev_variables.yml@self deployEnvironmentTemplate: devops/deploy_environment.yml@self </code>
    parameters:
      - name: sourcePipelineName
        type: string
        default: 'devops-med'
    
    resources:
      pipelines:
        - pipeline: SourcePipeline
          project: DEV
          source: ${{ parameters.sourcePipelineName }}
          trigger:
            branches:
              include:
                - test/pipeline
    extends:
      template: /cicdTemplates/pipeline.yml@global-pipelines
      parameters:
        variablesTemplate: devops/variables/global_variables.yml@self
        pipelineMode: ${{parameters.pipelineMode}}
      devEnvironment: dev
      devVariables: devops/ew/variables/dev_variables.yml@self
      deployEnvironmentTemplate: devops/deploy_environment.yml@self

I got error:

devops/dependantpipeline.yml (Line: 17, Col: 15): A template
expression is not allowed in this context

According to your description, you have two Azure DevOps pipelines (SourcePipeline and DependantPipeline) in the devops-med repository. The DependantPipeline is triggered by the SourcePipeline using a pipeline resource trigger.

The name of the SourcePipeline is devops-med, which is the same as the repository name, so you use source: 'devops-med' in the pipeline resource trigger.

If you don’t want to the hardcoded it in the pipeline resource trigger, you can change the pipeline to use a new name instead of the repository name.

You can also consider using the Generic webhook based triggers for YAML pipelines to trigger the second pipeline when the first one completes instead of using the pipeline resource triggers.

Here are the detailed steps:

  1. Create an “Incoming Webhook” service connection in Project settings > Service connections

  2. Create a Service hook web hook with work item related event in Project settings > Service Hooks and choose the Build completed event for the SourcePipeline devops-med.

    The Request Url is

    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    <code>"https://dev.azure.com/<ADO Organization>/_apis/public/distributedtask/webhooks/<WebHook Name>?api-version=6.0-preview"
    </code>
    <code>"https://dev.azure.com/<ADO Organization>/_apis/public/distributedtask/webhooks/<WebHook Name>?api-version=6.0-preview" </code>
    "https://dev.azure.com/<ADO Organization>/_apis/public/distributedtask/webhooks/<WebHook Name>?api-version=6.0-preview"
    

    The WebHook Name in the URL is the one you set in the service connection.

  3. Modify the DependantPipeline with the resource type webhooks. The pipeline will be triggered when the SourcePipeline devops-med is successful.

Sample YAML:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>trigger: none
resources:
repositories:
- repository: global-pipelines
type: git
name: global-pipelines
ref: test/pipeline
webhooks:
- webhook: MyWebhookTrigger ### Webhook name
connection: MyWebhookConnection ### Incoming webhook service connection name
</code>
<code>trigger: none resources: repositories: - repository: global-pipelines type: git name: global-pipelines ref: test/pipeline webhooks: - webhook: MyWebhookTrigger ### Webhook name connection: MyWebhookConnection ### Incoming webhook service connection name </code>
trigger: none

resources:
  repositories:
    - repository: global-pipelines
      type: git
      name: global-pipelines
      ref: test/pipeline
  webhooks:
    - webhook: MyWebhookTrigger         ### Webhook name
      connection: MyWebhookConnection    ### Incoming webhook service connection name

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật