1

If I create a variable like IsTrigger and the default value of this variable is false and this value can be set at queque time.

I wonder what happens if I give this variable true as value when I run a pipeline.

Can I trigger a different pipeline based on the value of this variable?

for example:

    eq(variables['IsTrigger', true]
  • do trigger different pipeline
0

3 Answers 3

0

You can do this with the Trigger Build Task available from VS Marketplace.

Or using REST API methods Run pipeline. For example via Invoke REST API task or with bash (script) task:

- bash: |
    curl \
      -H "Authorization: Bearer ${SYSTEM_ACCESSTOKEN}" \
      -X POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.0

  displayName: Trigger another pipeline
  condition: eq(variables['IsTrigger', true])
  env:
    SYSTEM_ACCESSTOKEN: $(system.accesstoken)
0

you can do by adding a trigger to the pipeline that you want to be triggered like


resources:
  'pipelines:
  - pipeline: MyCIAlias  
    source: MainPipeline
    trigger:    
      stages:        
      - MyStage

This will be triggered when the stage "MyStage" in your pipeline "MainPipeline" has completed.

In the MainPipeline on the MyStage you can set a condition that will skip the stage unless your "IsTrigger" variable is set to true, like

- stage: MyStage 
  dependsOn: 
  - Build
  displayName: Checklist Pre Production Release
  condition: | 
    eq(variables.IsTrigger, 'true')
    ```
0

You could also use the az commandline tool and the built-in AccessToken, when you need to trigger a Pipeline inside Azure DevOps on the same Organization.

- job:
  displayName: "Run Pipeline"
  steps:
  - bash: |
      az pipelines run --project 'PROJECT' --id 123456 --branch 'main' 
    displayName: 'Trigger Pipeline 123456'
    env:
      AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)

az pipelines run can also set parameters for a pipeline you want to trigger:
az pipelines run --project 'PROJECT' --id 123456 --branch 'main' --parameters 'param1=VALUE'
(The ones when you click "Run Pipeline" and can set/select in the UI in the Browser)
Documentation: https://learn.microsoft.com/en-us/cli/azure/pipelines?view=azure-cli-latest#az-pipelines-run

To find the ID of a pipeline:
az pipelines list -p "ProjectName" | ConvertFrom-Json | Select-Object -Property Id, Name, queueStatus | Where-Object { $_.Name -eq "PipelineName" }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.