HT1
HT1

Reputation: 81

Azure DevOps Pipeline does not trigger based on another branch

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.

Upvotes: 1

Views: 4547

Answers (2)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30353

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.

Upvotes: 4

Sujit Singh
Sujit Singh

Reputation: 829

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

Upvotes: 1

Related Questions