0

I have a following structure:

Test-A and Test-B projects created on Azure Devops. Test-A project's CI build pipeline will produce an artifact.

Test-B's pipeline uses the artifact produced by Test-A's CI pipeline in its build. I am able to download the build artifact of Test-A project and use it.

The problem I am facing here is I am unable to do a CI automatic trigger with project Test-A dependency in project Test-B i.e when ever I make changes and push the changes on to Test-A github repo or whenever I do a new build on Test-A I want the build for Test-B to start automatically.

I have read the documentation on Azure devops but they are not working.

Link for pipeline trigger

Link for pipeline multi-trigger

Below is my .yml file.

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'


resources:
  pipelines:
  - pipeline: JustAName
    project: Test-A
    source: Test-A_CI
    branch: master
    trigger: 
      branches:
        include: 
        - master

  repositories:
  - repository: justAnotherName
    type: github
    name: myGitRepo
    endpoint: myGitServiceConnection   
    trigger:    
      branches:  
        include:  
        - master

steps:

- task: DownloadPipelineArtifact@2
  inputs:
    buildType: 'specific'
    project: 'hashValue or Test-A'
    definition: '1'
    specificBuildWithTriggering: true
    buildVersionToDownload: 'latest'
    targetPath: '$(Agent.BuildDirectory)'

I am not sure where I am doing wrong or if it is a permission issue. I checked the logs to find any reference with the resources part in the yml but I had no luck.

Can someone suggest what is the best way to check what is the problem and resolve the issue.

Build completion option is disable in classic editor enter image description here

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
Phaneeth
  • 195
  • 1
  • 14
  • You should be using versioned packages for this. Project A's build produces an artifact, creates a package, and pushes the package to an artifacts feed. Project B consumes the artifact. Then you can use a "build completion" trigger and have Project B restore the required version from the artifacts feed. – Daniel Mann Dec 27 '19 at 17:46
  • @DanielMann Sure, I will try with the package feed. But why doesn't the CI process for Test-B is triggered immediately when I push some changes onto Test-A's github repo. I thought the git connection would do the trick – Phaneeth Dec 27 '19 at 17:54
  • Sorry if I wasnot clear with the question. I need the CI for B to start when either I push the changes on to A or when A's pipeline is triggered. – Phaneeth Dec 27 '19 at 17:55
  • @DanielMann I published the packages from project A to the feed. In project B I can click on artifacts and I can see the artifact there. But build completion is still the same, cant add. Am I missing something here ? – Phaneeth Dec 27 '19 at 21:19
  • Your pipeline trigger does not match Microsoft documentation, https://learn.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml#pipeline-triggers-1 Why? – Lex Li Dec 27 '19 at 23:15
  • @LexLi, Check this link, this is provided by microsoft too. Need project info to redirect to right project. https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#pipeline-resource – Phaneeth Dec 30 '19 at 15:10
  • I am able to see the build completion trigger when there are multiple pipelines in the same project but not when I have the pipelines in a different projects. Also having resources in yml is not triggering the CI build, it is only getting triggered when I add in build completion. I am not sure if this is a settings this. – Phaneeth Dec 30 '19 at 17:26

2 Answers2

1

For your issue , there is a custom task in the Azure DevOps marketplace: Trigger Azure DevOps pipeline. With this task you can trigger a build or release pipeline from another pipeline within the same project or organization but also in another project or organization.

To get started a PAT is needed with the appropriate rights to execute pipelines. Give the PAT the following rights depending on your scenario:

  • Triggering a Build: Build – Read & execute

When you have installed the extension, you can add this task into yaml. In the task setting ,you need to connect to a Azure DevOps Service connection. For detailed configuration, please refer to this.

steps:
- task: TriggerPipeline@1
  inputs:
    serviceConnection: 'triggerpipeline'
    project: 'Test-B'
    Pipeline: 'Build'
    buildDefinition: 'xxx'
    Branch: 'master'

enter image description here

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • This solves the issue but this is not what I am looking at. My Build completion option is disabled. Do you know how to enable that option. That should solve my issue – Phaneeth Dec 30 '19 at 15:57
  • If you want to use build completion triggers,you can only select any other build in the same project to be the triggering pipeline. This is not applicable if you want to trigger the pipeline in different projects. – Hugh Lin Dec 31 '19 at 01:35
  • What about pipeline parameters? Can you add an example using that? Thanks – Alejandro Galera Feb 02 '23 at 17:39
1

The build completion option in the pipeline classic editor is limited to the pipelines within the same project. So it won't work for your scenario(the triggering pipeline and triggered pipeline reside in different project) even if it is enabled.

For issue build completion option is disabled. You can report this issue here. Click report a problem and select Azure Devops.

Resources pipeline trigger doesnot work properly sometimes. This similar issue has submitted to Microsoft by some other users. You can follow and vote on these cases or create a new one. Build Completion Triggers not working, Pipeline trigger not working as expressed in documentation

You can follow the workaround which using task TriggerPipeline given by @Hugh. You can also add a powershell task to call the rest api to queue another build pipeline. You can check this thread for example scripts

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43