I would like to determine docker tag depending on building source branch.
What I’ve done so far:
<code>variables:
- name: isMain
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.releaseBranchName }}')]
readonly: true
- name: isStaging
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.stagingBranchName }}')]
readonly: true
- name: isDevelop
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.buildBranchName }}')]
readonly: true
- name: shouldPublish
value: $[or(variables['isMain'], variables['isStaging'], variables['isDevelop'])]
readonly: true
- name: tag
${{ if variables['isMain'] }}:
value: $[format('release.{0}', variables['Build.BuildNumber'])]
${{ elseif variables['isStaging'] }}:
value: $[format('staging.{0}', variables['Build.BuildNumber'])]
${{ else }}:
value: $[format('build.{0}', variables['Build.BuildNumber'])]
readonly: true
</code>
<code>variables:
- name: isMain
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.releaseBranchName }}')]
readonly: true
- name: isStaging
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.stagingBranchName }}')]
readonly: true
- name: isDevelop
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.buildBranchName }}')]
readonly: true
- name: shouldPublish
value: $[or(variables['isMain'], variables['isStaging'], variables['isDevelop'])]
readonly: true
- name: tag
${{ if variables['isMain'] }}:
value: $[format('release.{0}', variables['Build.BuildNumber'])]
${{ elseif variables['isStaging'] }}:
value: $[format('staging.{0}', variables['Build.BuildNumber'])]
${{ else }}:
value: $[format('build.{0}', variables['Build.BuildNumber'])]
readonly: true
</code>
variables:
- name: isMain
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.releaseBranchName }}')]
readonly: true
- name: isStaging
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.stagingBranchName }}')]
readonly: true
- name: isDevelop
value: $[eq(variables['Build.SourceBranch'], 'refs/heads/${{ parameters.buildBranchName }}')]
readonly: true
- name: shouldPublish
value: $[or(variables['isMain'], variables['isStaging'], variables['isDevelop'])]
readonly: true
- name: tag
${{ if variables['isMain'] }}:
value: $[format('release.{0}', variables['Build.BuildNumber'])]
${{ elseif variables['isStaging'] }}:
value: $[format('staging.{0}', variables['Build.BuildNumber'])]
${{ else }}:
value: $[format('build.{0}', variables['Build.BuildNumber'])]
readonly: true
which evaluates like this :
<code> isMain:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/main')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/main')
Expanded: eq('refs/heads/cd', 'refs/heads/main')
Result: 'False'
isStaging:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/cd')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/cd')
Expanded: eq('refs/heads/cd', 'refs/heads/cd')
Result: 'True'
isDevelop:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/develop')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/develop')
Expanded: eq('refs/heads/cd', 'refs/heads/develop')
Result: 'False'
shouldPublish:
Parsing expression: <or(variables['isMain'], variables['isStaging'], variables['isDevelop'])>
Evaluating: or(variables['isMain'], variables['isStaging'], variables['isDevelop'])
Expanded: or('False', variables['isStaging'], variables['isDevelop'])
Result: 'True'
tag:
Parsing expression: <format('release.{0}', variables['Build.BuildNumber'])>
Evaluating: format('release.{0}', variables['Build.BuildNumber'])
Result: 'release.20240531.11'
</code>
<code> isMain:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/main')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/main')
Expanded: eq('refs/heads/cd', 'refs/heads/main')
Result: 'False'
isStaging:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/cd')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/cd')
Expanded: eq('refs/heads/cd', 'refs/heads/cd')
Result: 'True'
isDevelop:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/develop')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/develop')
Expanded: eq('refs/heads/cd', 'refs/heads/develop')
Result: 'False'
shouldPublish:
Parsing expression: <or(variables['isMain'], variables['isStaging'], variables['isDevelop'])>
Evaluating: or(variables['isMain'], variables['isStaging'], variables['isDevelop'])
Expanded: or('False', variables['isStaging'], variables['isDevelop'])
Result: 'True'
tag:
Parsing expression: <format('release.{0}', variables['Build.BuildNumber'])>
Evaluating: format('release.{0}', variables['Build.BuildNumber'])
Result: 'release.20240531.11'
</code>
isMain:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/main')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/main')
Expanded: eq('refs/heads/cd', 'refs/heads/main')
Result: 'False'
isStaging:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/cd')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/cd')
Expanded: eq('refs/heads/cd', 'refs/heads/cd')
Result: 'True'
isDevelop:
Parsing expression: <eq(variables['Build.SourceBranch'], 'refs/heads/develop')>
Evaluating: eq(variables['Build.SourceBranch'], 'refs/heads/develop')
Expanded: eq('refs/heads/cd', 'refs/heads/develop')
Result: 'False'
shouldPublish:
Parsing expression: <or(variables['isMain'], variables['isStaging'], variables['isDevelop'])>
Evaluating: or(variables['isMain'], variables['isStaging'], variables['isDevelop'])
Expanded: or('False', variables['isStaging'], variables['isDevelop'])
Result: 'True'
tag:
Parsing expression: <format('release.{0}', variables['Build.BuildNumber'])>
Evaluating: format('release.{0}', variables['Build.BuildNumber'])
Result: 'release.20240531.11'
I do not understand why the tag
variable enters the first condition as “isMain” is set to false.
Could you please help?