0
votes

I'm trying to trigger a deployment pipeline after a build pipeline completes, so that I can have the status of the pipelines kept separate (the current UI presents confusing status values when everything is in the same pipeline in stages). The deployment pipeline has a resource definition as outlined in the documentation and that refers to the build pipeline. The build pipeline is named "BuildTheApp" and is in the root pipeline folder. Screen shot showing the name of the build pipeline is "BuildTheApp".

The resource dependency on the build pipeline is defined in the deployment pipeline as below, and there are no other triggers defined, and there is not any override of the yaml trigger in the pipeline definition:

resources:
  pipelines:
  - pipeline: BuildPipeline
    source: BuildTheApp
    trigger: true

pipeline: BuildPipeline is just the name for use within the deployment pipeline.
source: BuildTheApp refers to the name of the build pipeline.
I know that it is picking up the name of the build pipeline correctly because when I created another pipeline named BuildTheApp in another folder, the deploy pipeline gave an error about matching multiple potential definitions.

The deploy pipeline never executes after the build pipeline is run. It doesn't matter whether the build pipeline executed because of its branch-change trigger or if it is executed manually. The deploy pipeline always executes when the branch changes, at the same time as the build pipeline. In the deploy pipeline, echo 'Build reason $(Build.Reason)' results in Build reason IndividualCI, proving that the pipeline is executed via a CI trigger.

I don't know why the deploy pipeline is executing on code changes without any trigger to do so. The default behavior should be to not execute. And of course, it's not executing when the build pipeline completes, either.

Template files are used in both the build and the deploy pipelines to reduce redundant code.

1

1 Answers

1
votes

Azure Pipelines Resource Pipeline should execute on build pipeline completion but executes on code change instead

This behavior is by designed and is not a bug. There is no way to fix it at present.

You could get the detail state from the document Pipeline triggers:

When you specify both CI triggers and pipeline triggers, you can expect new runs to be started every time (a) an update is made to the repository and (b) a run of the upstream pipeline is completed. Consider an example of a pipeline B that depends on A. Let us also assume that both of these pipelines use the same repository for the source code, and that both of them also have CI triggers configured. When you push an update to the repository, then:

  • A new run of A is started.

  • At the same time, a new run of B is started. This run will consume the previously produced artifacts from A.

  • As A completes, it will trigger another run of B.

To prevent triggering two runs of B in this example, you must remove its CI trigger or pipeline trigger.

When I tested it, it worked as expected. That the reason why you get Build reason is IndividualCI.

If you want to trigger the deployment pipeline after a build pipeline completed, you could use dependsOn will enforce sequential jobs build:

jobs:
- job: Debug
  steps:
  - script: echo hello from the Debug build
- job: Release
  dependsOn: Debug
  steps:
  - script: echo hello from the Release build

Check the official doc Dependencies.

Hope this helps.