Search code examples
azure-devopsazure-pipelinescicdazure-pipelines-yamlazure-pipelines-build-task

Will CD steps run when we raise a PR if we have build validation enabled?


I have a pipeline in Azure DevOps, I have CD steps in it like stopping IIS, Deploying my code etc I was wondering if i use that pipeline in build validation will it deployed by those CD steps in my pipeline even before PR completion? I just want to run CI steps.

I didn't run it because I dont want to deploy the code directly.


Solution

  • I was wondering if i use that pipeline in build validation will it deployed by those CD steps in my pipeline even before PR completion?

    Yes. By default, if you add the pipeline to Build Validation of PR, it will run all steps in the pipeline(Inclduing CD steps).

    I just want to run CI steps.I didn't run it because I dont want to deploy the code directly.

    To meet your requirement, you can add the Condition to the CD steps.

    We can use the variable: Build.Reason to determine if the pipeline is triggered by Pull Request Build validation.

    For example: condition: ne(variables['Build.Reason'], 'PullRequest')

    steps:
    - task: stopIISstep
      condition: ne(variables['Build.Reason'], 'PullRequest')
    

    When the pipeline is triggered by Pull Request Build validation, the CD steps will be skipped. And CI steps will run as expected.

    On the other hand, you can also consider splitting the CI and CD steps into two pipelines. Then you can add the CI step Pipeline to the Pull Request Build Validation.