I’m looking for the reason why the DEV Environment is not executed immediately after the Testing stage. The general rule is that I have two pipelines: the first one does only Testing, then it triggers the second pipeline, which should perform the actual deployment using Terraform on the Dev Environment. The first part works, i.e., the first pipeline triggers the second one correctly, but the triggered one does not start the Dev Environment.
pipeline.yaml
name: MySource
resources:
repositories:
- repository: Library
type: git
name: Library
ref: test/pipeline
trigger:
batch: true
branches:
include:
- test/pipeline
parameters:
- name: pipelineMode
displayName: Pipeline Mode
type: string
default: main
values:
- auto
- feature
- main
- release
<rest_of_the code>
It triggers that one below:
dependant_pipeline.yaml
trigger: none
resources:
repositories:
- repository: Library
type: git
name: Library
ref: test/pipeline
pipelines:
- pipeline: test-triggered
project: DEV
source: 'library'
trigger:
branches:
include:
- test/pipeline
parameters:
- name: pipelineMode
displayName: Pipeline Mode
type: string
default: main
values:
- auto
- feature
- main
- release
variables:
- template: /templates/options.yml
stages:
- stage: Testing
displayName: Testing
- template: /templates/build.yml
parameters:
pipelineOptions:
pipelineMode: ${{variables.pipelineMode}}
sourceBranchType: ${{variables['Pipeline.SourceBranchType']}}
normalizedSourceBranch: $(Pipeline.NormalizedSourceBranch)
isDeploymentPlanned: ${{variables.isDeploymentPlanned}}
isDetectChangesEnabled: ${{ne(parameters.detectChangesFolders, '')}}
isIgnoreServicePermissions: ${{parameters.ignoreServicePermissions}}
devEnvironment: ${{parameters.devEnvironment}}
devVariables: ${{parameters.devVariables}}
tstEnvironment: ${{parameters.tstEnvironment}}
tstVariables: ${{parameters.tstVariables}}
tstTestTemplate: ${{parameters.tstTestTemplate}}
tstTests: ${{parameters.tstTests}}
intEnvironment: ${{parameters.intEnvironment}}
intVariables: ${{parameters.intVariables}}
prdEnvironment: ${{parameters.prdEnvironment}}
prdVariables: ${{parameters.prdVariables}}
environmentTemplate: ${{parameters.deployEnvironmentTemplate}}
deployParameters: ${{parameters.deployParameters}}
The part of triggering one pipeline by another works, with some additional steps done on Azure DevOps.
For me issues starts somewhere below.
/templates/build.yml
<...>
stages:
- ${{ if ne(parameters.devEnvironment, '') }}:
- stage: DEV
displayName: DEV Env
dependsOn: Testing
condition: and(succeeded(), eq('${{parameters.pipelineOptions.pipelineMode}}', 'main'))
variables:
- template: ${{parameters.devVariables}}
- name: environment
value: ${{parameters.devEnvironment}}
readonly: true
- name: env
value: dev
readonly: true
pool:
name: $(agentPool)
jobs:
- template: ${{parameters.environmentTemplate}}
parameters:
pipelineOptions: ${{parameters.pipelineOptions}}
environment: ${{variables.environment}}
env: ${{variables.env}}
${{each param in parameters.deployParameters}}:
${{param.key}}: ${{param.value}}
<...>
/templates/options.yml
parameters:
- name: pipelineMode
type: string
variables:
- name: Pipeline
value:
readonly: true
- name: Pipeline.NormalizedSourceBranch
value: ${{replace(replace(coalesce(variables['System.PullRequest.SourceBranch'], variables['Build.SourceBranch']),'refs/heads/',''),'/','__')}}
readonly: true
- name: Pipeline.SourceBranchType
readonly: true
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }}:
value: "main"
${{ elseif startsWith(variables['Build.SourceBranch'], 'refs/heads/release/') }}:
value: "release"
${{ else }}:
value: "feature"
- name: pipelineMode
readonly: true
${{ if eq(parameters.pipelineMode, 'auto') }}:
value: ${{variables['Pipeline.SourceBranchType']}}
${{ else }}:
value: ${{parameters.pipelineMode}}
For testing purposes, I created my own branch named test/pipeline, and I noticed that when I added it as a reference in the pipeline, the problems started. So, the cause is probably somewhere here. Previously, the pipeline was set to main, and the entire workflow worked without issues. However, I need to do this in my own branch, which is why test/pipeline is set in the pipeline.
I shortened the code to the part that I believe is causing the Dev Env not to execute. I hope I didn’t cut out too much.
With my many attempts all of them lead to the lack of Dev env. execution.