Below are some hints to use Azure pipeline
1. If a variable is dependent on another, then the latter should be a constant. If both are evaludated from a non-constant expression then the value may not be correct. E.g.
variables:
a: 1
b: a+1
c: b+1
2. Quote the parameters otherwise the value may not be considered as string.
E.g. stage S1 is fine whereas S2 will throw an error.
parameters:
- name: envName
displayName: environment name
type: string
default: prod
values:
- prod
stages:
- stage: S1
condition: eq('${{parameters.envName}}', 'prod')
- stage: S2
condition: eq( ${{parameters.envName}} , 'prod')
3. Use |
for convenience. E.g.
condition: |
and (
succeeded(),
eq('$(version)', '1.2')
)
script: |
echo aa
echo bb
4. Use single quotes to escape :
in script.
E.g. Script S1 is fine whereas S2 throws errors
- script: 'echo "TODO: Add tests" here'
displayName: S1
- script: echo '"TODO: Add tests" here'
displayName: S2
5. Use dependsOn
to ensure job dependency. succeeded()
does not ensure that. E.g.
- job: j1
displayName: Build app
- job: j2
displayName: Deploy app
dependsOn: j1