1

I have a DevOps pipeline placed in the "develop" branch but I want it to be triggered based on changes from another branch "adf_publish". The trigger section is as follows:

trigger:
  branches:
    include:
      - adf_publish

It is not working for me. However, if I place this script in the "adf_publish" branch, then whenever there is a change, this script is triggered successfully.

I have followed the syntax based on Microsoft documentation:

Continuous integration (CI) triggers cause a pipeline to run whenever you push an update to the specified branches or you push specified tags.

There seems to be a lot of people having related problem but I did not see a clear solution so far, I have even tried changing settings on the classic editor as suggested by this post, but it is still not working for me. Any ideas will be appreciated.

HT1
  • 61
  • 2
  • 11

2 Answers2

2

Continuous integration (CI) triggers can only trigger the pipeline to run against its own branch, which means if you enable ci triggers for adf_publish branch(place this script in the "adf_publish" branch), whenever you push an update to adf_publish, the pipeline will be executed against adf_publish branch(not develop branch).

Pipeline completion triggers won't work. The reason is stated as below:

If the two pipelines are in the same repository, the triggered pipeline version in the same branch as the triggering pipeline is run, even if that branch is different than the Default branch for manual and scheduled builds, and even if that version does not have branch filters that match the completed pipeline's branch.

So if you set up the pipeline to run on the completion of the build of adf_publish branch. The same branch adf_publish branch will be used as the triggered pipeline source branch.

If you want the pipeline to build develop branch, when there are changes being pushed to branch "adf_publish". You can try below workaround using Trigger build task.

1, Enable CI trigger for adf_publish branch.(In your pipeline edit page, switch to adf_publish branch to add below in the azure-pipelines.yaml file in adf_publish branch)

enter image description here

2,Add Trigger build task to the the build definition of adf_publish branch( edit the azure-pipelines.yaml file in adf_publish branch). See below example:

 - task: TriggerBuild@3
    inputs:
      definitionIsInCurrentTeamProject: true
      buildDefinition: '$(Build.DefinitionName)'  # builddefintion name 
      queueBuildForUserThatTriggeredBuild: true
      useSameBranch: false
      branchToUse: 'develop'
      authenticationMethod: 'Personal Access Token'
      enableBuildInQueueCondition: false
      password: $(system.accesstoken)

Note: The parameter useSameBranch need to set to false. And branchToUse need to set to develop in order to trigger the same pipeline to build on develop branch.

You can also run rest api in a script task to trigger the pipeline to build against develop branch.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Thanks @LeviLu for the explanation. It aligns with my initial findings as well. If this is the case, I feel this behaviour defeats the purpose of having the pipeline parameter "trigger" since you cannot select a different branch? (I do realize it offers additional fine tuning such as "include"/"exclude" options). As well, this definition of CI Trigggers documented by MSFT would be misleading: "Continuous integration (CI) triggers cause a pipeline to run whenever you push an update to the specified branches or you push specified tags". I will move my pipeline into adf_publish branch. – HT1 Mar 08 '21 at 14:03
  • @HT1 This is the expected behavior. Users would expect pipeline being triggered to build A branch when changes pushed to A branch. Trigger to build B branch when commit to A branch is not a general case.The document indeed doesn't make this clearly stated. – Levi Lu-MSFT Mar 09 '21 at 02:15
  • @HT1 Since this issue is fixed, Could accept above answer if you think it qualifies as the answer? Or you can post out your own answer. – Levi Lu-MSFT Mar 10 '21 at 09:44
  • Lu, i have upvoted and accepted your answer. Thank you. – HT1 Mar 10 '21 at 13:43
1

yaml pipeline trigger is almost good, there is just one space extra in branch name line.

It should be like this:

trigger:
  branches:
    include:
    - adf_publish
Sujit Singh
  • 799
  • 6
  • 11
  • Thanks @sujit singh for catching that. I modified as you suggested but unfortunately it did not work, I tried updating adf_publish branch several times, it still did not activate this trigger :( – HT1 Mar 07 '21 at 17:46
  • We have exactly same configuration and it is working fine. Did you push some change in adf_publish branch to test? – Sujit Singh Mar 12 '21 at 18:15
  • yes I did many times. In your case, is your YAML pipeline stored in the adf_publish branch or the standard master/develop branch? – HT1 Mar 13 '21 at 21:57
  • It is stored in adf_publish branch. We create a branch off adf_publish for any pipeline changes. – Sujit Singh Mar 15 '21 at 05:52
  • 1
    That makes sense now. Mine also worked that way as designed, but I was hoping I could find a way to store the pipeline in develop branch, yet can trigger when something changes in adf_publish. I now know that it is not designed to work that way. – HT1 Mar 16 '21 at 02:13
  • @SujitSingh Are you sure this has an effect? Could you please link any source to back this answer? – RukshanJS Apr 11 '23 at 08:20
  • @RukshanJS Yes, it does work. Source for the trigger is there in the answer, is it not working for you? – Sujit Singh Apr 12 '23 at 09:56