Chris Brennan
Chris Brennan

Reputation: 3

Is there a way to bypass dependencies in an Azure multistage pipeline?

 - stage: DeployToIVT
    displayName: Deploy ${{join(' AND ', parameters.ivtEnv )}}
    dependsOn:
    - Build
    condition: |
        and
        (
          eq(dependencies.Build.result, 'Succeeded'),
          
            
            or
            (
              
              startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'),
              startsWith(variables['Build.SourceBranch'], 'refs/heads/refresh/')
            )   
        )

I have a master.yml that we use for multistage pipelines. The stage that deploys to QA is conditional based with a dependency on a successful build. Is there a way to uncheck build and just have the deploy stage checked in order to bypass that build dependency? When I try that it skips that stage all together and does nothing. I have tried adding a condition to say

  in(dependencies.Build.result, 'Succeeded', 'SucceededWithIssues', 'Skipped')

But the above does not work either.

Thanks

Upvotes: 0

Views: 649

Answers (1)

bryanbcook
bryanbcook

Reputation: 18363

My team does something similar. We skip over the build stage and reuse artifacts from previous builds or bypass entire environments if we need to do a hotfix, etc.

We use a technique similar to following, where we add a variable at queue time that can shortcut conditions:

 - stage: Build
   displayName: 'CI'
   condition: ne(variables['deployWithoutBuild'], 'true')
   ...
 
 - stage: DeployToIVT
   displayName: Deploy ${{join(' AND ', parameters.ivtEnv )}}
   dependsOn:
    - Build
   condition: |
      or(
        and(
          in(dependencies.Build.result, 'Succeeded','SucceededWithIssues','Skipped',''),         
          or(
              startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'),
              startsWith(variables['Build.SourceBranch'], 'refs/heads/refresh/')
            )   
        ),
        eq(variables['deployWithoutBuild'], 'true')
      )

I believe checking for a '' build result was to accommodate if the stage was not included in the list of stages to run.

Upvotes: 2

Related Questions