1

I want to write if condition that satisfies below:

  1. running axe analysis should be set to true
  2. Build reason should be pull request
  3. source branch should be develop branch (when the user select any other branch[ ex:release] axe should not run)
  4. custom tag value should not be null

i tried with the below conditions

- ${{ if or(eq(parameters.axe_flag, true) , eq(variables['Build.Reason'], 'PullRequest')) }}: 

- ${{ if and(not(eq(parameters.cust_tagName, 'null' )) ,startsWith(variables['Build.SourceBranch'], 'refs/heads/develop')) }}:

condition: and(succeeded(), or(startsWith(variables['Build.SourceBranch'], 'refs/heads/develop'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'), startsWith(variables['Build.SourceBranch'], 'refs/heads/develop-map')))

Multiple if conditions are not working. keep getting below error

Exactly 1 parameter(s) were expected following the directive 'if'. Actual parameter count: 2
/templates/build.yml@templates (Line: 40, Col: 3): Unexpected value '${{ if or(eq(parameters.sonarqube_flag, true) , eq(variables['Build.Reason'], 'PullRequest')), and(not(eq(parameters.cust_tagName, 'null' )) ,startsWith(variables['Build.SourceBranch'], 'refs/heads/develop')) }}'
/templates/build.yml@templates: (Line: 46, Col: 14, Idx: 1828) - (Line: 46, Col: 14, Idx: 1828): Mapping values are not allowed in this context.

first if statement with or condition works perfectly without errors when i add the second if statement with and condition, keep getting the below error. Any advise on how to handle multiple conditions would be really helpful. Thanks in advance.

syndy1989
  • 403
  • 10
  • 25

1 Answers1

1

It seems that you are adding the template condition (if statement) where scalar value is allowed - note that minus in the beginning of your if statement - which makes it non-scalar. Also check the error "Mapping values are not allowed in this context"

This is a common mistake in general YAML templates - see here

YAML mapping values are not allowed in this context

If the full YAML was shared then it could have been better, as I am just providing solution on the basis of error message

scorpio
  • 1,587
  • 2
  • 15
  • 27