2
votes

Unable to trigger pipeline upon completion of other pipeline

Original

I am trying to build several release pipelines for our angular apps within devops yaml pipelines. We are using an Nx workspace, so its important to be able to trigger these pipelines at the end of the workspace build.

Here is the sample doc code provided by Microsoft (https://docs.microsoft.com/en-us/azure/devops/pipelines/process/pipeline-triggers?view=azure-devops&tabs=yaml)

# this is being defined in app-ci pipeline
resources:
  pipelines:
  - pipeline: securitylib   # Name of the pipeline resource
    source: security-lib-ci # Name of the triggering pipeline
    trigger: 
      branches:
      - releases/*
      - master

Here is my full pipeline at this point:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger: none

resources:
  pipelines:
  - pipeline: WorkspaceBuild
    source: OtherPipeline
    project: CommonProject
    trigger: 
      branches: 
      - master
pool:
  vmImage: 'ubuntu-latest'

steps:

- task: DownloadBuildArtifacts@0
  inputs:
    buildType: 'current'
    downloadType: 'single'
    artifactName: 'web-framework'
    downloadPath: '$(System.ArtifactsDirectory)'

- script: |
    cd $(System.ArtifactsDirectory)
    dir .
  displayName: 'Run a one-line script'

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

Update

Ok, fixing the naming allows each pipeline to run. However, the build pipeline still does not trigger the deployment pipeline.

Respective Pipelines (UPS1_Workspace build, wf-stg deploys)

Deployment pipeline resources tag

Deployment pipeline triggers settings

Update 2

Hey, this is still not working. I removed all of the CI settings from the triggers ui panel, and ensured that the override box was not ticked. Here are some more images to help with diagnosis

Pipeline Status's

Triggering Pipeline Step Results

Start of triggered pipeline's yml file

2
Is the build pipeline publishing any artifact using the PublishPipelineArtifact task?Giulio Vian
Yeah, it is at the end. I have verified the pipeline publishes, and if I run the triggered pipeline manually it downloads itCraigory Coppola

2 Answers

0
votes

How should I trigger one pipeline at the end of another? Using the example from msdocs leads to “pipeline resource input must be valid” error

According to the error message pipeline resource input must be valid, It seems Azure devops doesn't pick the name of the pipeline as mentioned in the yaml file.

It should be the name of the pipeline. To resolve this issue, you could try to go to the Triggers of the pipeline OtherPipeline and rename the pipeline and use that name in the your full pipeline:

enter image description here

enter image description here

If above not resolve your issue, please provide some screenshots about your YAML name and the real value in the full pipeline (Just hide personal information).

Update:

Ok, fixing the naming allows each pipeline to run. However, the build pipeline still does not trigger the deployment pipeline.

In the screenshot you provided, there are three points that need your attention.

First, since you are using the YAML, we do not need to set the configuration build completion triggers in the UI:

So, we need to remove it from UI:

enter image description here

That because:

Previously, you may have navigated to the classic editor for your YAML pipeline and configured build completion triggers in the UI. While that model still works, it is no longer recommended. The recommended approach is to specify pipeline triggers directly within the YAML file. Build completion triggers as defined in the classic editor have various drawbacks, which have now been addressed in pipeline triggers. For instance, there is no way to trigger a pipeline on the same branch as that of the triggering pipeline using build completion triggers.

Second, we just need to provide the branch name without full path, so the YAML should be:

resources:
  pipelines:
  - pipeline: WorkspaceBuild
    source: UPS1_Workspace
    project: UPS1_Workspace
    trigger: 
      branches: 
      - master
      - azure-pipelines-wf

Third, if the triggering pipeline is in same Azure DevOps project, you could omit specify the project name.

resources:
  pipelines:
  - pipeline: WorkspaceBuild
    source: UPS1_Workspace
    trigger: 
      branches: 
      - master
      - azure-pipelines-wf

If the triggering pipeline is in another Azure DevOps project, you must specify the project name using project: OtherProjectName. If the triggering pipeline is in another Azure DevOps organization, you must also create a service connection to that project and reference it in your pipeline resource. For more information, see pipeline resource.

Please check the document Trigger one pipeline after another for some more details.

Update2:

According to the image you provide:

enter image description here

The trigger branch should include the branch where the pipeline UPS1_Workspace is located instead of the pipeline wf-stg.yml.

For example, my pipeline UPS1_Workspace under the branch DemoBranch:

enter image description here

Then I add the branch DemoBranch in the wf-stg.yml as trigger branch:

resources:
  pipelines:
  - pipeline: WorkspaceBuild
    source: UPS1_Workspace
    trigger: 
      branches: 
      - master
      - DemoBranch
0
votes

Having just solved this error Pipeline resource pipelinename must be valid - what it actually means is that the source: pipeline name given is invalid.

There seems to be no UI on AzureDevOps in 2021 - it's all YAML, which makes things simpler.

Assuming both repositories are in the same high-level project grouping:

  1. Upstream repository has a pipeline (the source pipeline) which has an arbitrary name - let's say this is named My Upstream Pipeline (release). No special configuration is required in this repository or its pipeline.

  2. Downstream repository has a pipeline that you want triggered after the upstream has built successfully on any 'release/' branch. You add the following incantation to its yaml:

resources:
  pipelines:
    - pipeline: alias_name
      source: 'My Upstream Pipeline (release)'
      trigger:
        branches:
          - release/*

If you typo 'My Upstream Pipeline (release)' then you'll get the error Pipeline resource alias_name must be valid.

The branch of the downstream repo that will build is the default branch - I don't think there's any way to alter that other than by changing the default branch.

If you need to do any extra processing in the downstream pipeline based on the identity of the triggering pipeline (for example, to pass a published artifact down), I'd recommend choosing alias_name to match the name of the upstream repository, also use characters which are legal within environment variables. This is because ADO makes the information about that upstream triggering project available to the downstream pipeline via a number of environment variables, with alias_name incorporated as part of those variable names:

  • RESOURCES_TRIGGERINGALIAS = alias_name

Then the following variables have alias_name uppercased to ALIAS_NAME:

  • RESOURCES_PIPELINE_ALIAS_NAME_PROJECTID - the upstream project ID
  • RESOURCES_PIPELINE_ALIAS_NAME_PIPELINEID - the upstream pipeline ID
  • RESOURCES_PIPELINE_ALIAS_NAME_RUNID -the upstream build or run ID

You can then construct the URL of the upstream (triggering) pipeline with: PIPELINEURL="${SYSTEM_TEAMFOUNDATIONSERVERURI}${RESOURCES_PIPELINE_ALIAS_NAME_PROJECTID}/_build?buildId=${RESOURCES_PIPELINE_ALIAS_NAME_RUNID}"

and fetch a published artifact from it using

          - task: DownloadPipelineArtifact@2
            name: DownloadFromUpstream
            displayName: 'Download file from upstream'
            condition: eq(variables['Build.Reason'], 'ResourceTrigger')
            inputs:
              source: specific
              project: $(RESOURCES_PIPELINE_ALIAS_NAME_PROJECTID)
              pipeline: $(RESOURCES_PIPELINE_ALIAS_NAME_PIPELINEID)
              runId: $(RESOURCES_PIPELINE_ALIAS_NAME_RUNID)
              preferTriggeringPipeline: true
              artifact: 'published-artifact-name'
              path: .

Refereces:

  1. https://docs.microsoft.com/en-us/azure/devops/pipelines/process/pipeline-triggers
  2. https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#the-pipeline-resource-metadata-as-predefined-variables