Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trigger individual stages in different pipelines one after another

I have 2 pipelines: Infra and Code. Both share 1 code repository.

Infra is triggered when bicep code changes and azure resources must be redeployed.
Code is triggered when code changes and must be updated to function apps etc.

This is to reduce infra deployments when nothing changes, so run times get optimized.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Both pipelines have 2 stages: one for Dev env and one for Prod env.
Prod env has approval that I dismiss if I just want to test code in Dev.

Now, when infra changes the function app code gets wiped away and Code pipeline should be run always after it.

But if I dismiss the approval, infra pipeline does not complete and a pipeline trigger in code won’t work

# infra pipeline yaml
stages:
- stage: Dev
  jobs:
  - template: 'deployInfraToEnv.yaml'
    parameters: ...

- stage: Prod
  jobs:
  - template: 'deployInfraToEnv.yaml'
    parameters: ...
# code pipeline yaml
resources:
  pipelines:
    - pipeline: Infra
      source: 'Infra pipeline'
      trigger: true # run after infra pipeline completes

stages:
- stage: Dev
  jobs:
    - template: 'deployCodeToEnv.yaml'
      parameters: ...
  
- stage: Prod
  jobs:
    - template: 'deployCodeToEnv.yaml'
      parameters: ...

Is it possible to somehow setup pipelines so that

Infra pipeline dev stage completes -> Run code pipeline dev stage
Infra pipeline prod stage completes -> Run code pipeline prod stage

Or should I just give up and integrate both infra and code deployments into one pipeline.

>Solution :

So if I understood correctly, you have 2 scenarios:

  1. Bicep code changes: redeploy infrastructure + code (Function App)
  2. Application code changes: redeploy code (Function App)

I suggest using a separate pipeline for each scenario.

Pipeline 1 – Bicep code changes

Considering you are already using templates like deployCodeToEnv.yaml that can be easily reused across pipelines, you can keep things simple and use these templates in the first pipeline.

Something like:

# infra pipeline yaml
# When infrastructure changes deploy BOTH infra and code

stages:
- stage: DevInfra
  jobs:
  - template: 'deployInfraToEnv.yaml'
    parameters: ...

- stage: DevCode
  dependsOn: DevInfra
  jobs:
    - template: 'deployCodeToEnv.yaml'
      parameters: ...

- stage: ProdInfra
  jobs:
  - template: 'deployInfraToEnv.yaml'
    parameters: ...

- stage: ProdCode
  dependsOn: ProdInfra
  jobs:
    - template: 'deployCodeToEnv.yaml'
      parameters: ...

Pipeline 2 – Application code changes

Second pipeline stays basically the same, with the exception of the trigger (removed):

# When application code changes deploy code ONLY

stages:
- stage: Dev
  jobs:
    - template: 'deployCodeToEnv.yaml'
      parameters: ...

- stage: Prod
  jobs:
    - template: 'deployCodeToEnv.yaml'
      parameters: ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading