Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
[release/v7.4] Fix condition syntax for StoreBroker package tasks in MSIX pipeline #26434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TravisEz13
merged 1 commit into
PowerShell:release/v7.4
from
TravisEz13:backport/release/v7.4/26427-1fd3ea83
Feb 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
223 changes: 223 additions & 0 deletions
223
.github/instructions/onebranch-condition-syntax.instructions.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| --- | ||
| applyTo: ".pipelines/**/*.{yml,yaml}" | ||
| --- | ||
|
|
||
| # OneBranch Pipeline Condition Syntax | ||
|
|
||
| ## Overview | ||
| Azure Pipelines (OneBranch) uses specific syntax for referencing variables and parameters in condition expressions. Using the wrong syntax will cause conditions to fail silently or behave unexpectedly. | ||
|
|
||
| ## Variable Reference Patterns | ||
|
|
||
| ### In Condition Expressions | ||
|
|
||
| **✅ Correct Pattern:** | ||
| ```yaml | ||
| condition: eq(variables['VariableName'], 'value') | ||
| condition: or(eq(variables['VAR1'], 'true'), eq(variables['VAR2'], 'true')) | ||
| condition: and(succeeded(), eq(variables['Architecture'], 'fxdependent')) | ||
| ``` | ||
|
|
||
| **❌ Incorrect Patterns:** | ||
| ```yaml | ||
| # Don't use $(VAR) string expansion in conditions | ||
| condition: eq('$(VariableName)', 'value') | ||
|
|
||
| # Don't use direct variable references | ||
| condition: eq($VariableName, 'value') | ||
| ``` | ||
|
|
||
| ### In Script Content (pwsh, bash, etc.) | ||
|
|
||
| **✅ Correct Pattern:** | ||
| ```yaml | ||
| - pwsh: | | ||
| $value = '$(VariableName)' | ||
| Write-Host "Value: $(VariableName)" | ||
| ``` | ||
|
|
||
| ### In Input Fields | ||
|
|
||
| **✅ Correct Pattern:** | ||
| ```yaml | ||
| inputs: | ||
| serviceEndpoint: '$(ServiceEndpoint)' | ||
| sbConfigPath: '$(SBConfigPath)' | ||
| ``` | ||
|
|
||
| ## Parameter References | ||
|
|
||
| ### Template Parameters (Compile-Time) | ||
|
|
||
| **✅ Correct Pattern:** | ||
| ```yaml | ||
| parameters: | ||
| - name: OfficialBuild | ||
| type: boolean | ||
| default: false | ||
|
|
||
| steps: | ||
| - task: SomeTask@1 | ||
| condition: eq('${{ parameters.OfficialBuild }}', 'true') | ||
| ``` | ||
|
|
||
| Note: Parameters use `${{ parameters.Name }}` because they're evaluated at template compile-time. | ||
|
|
||
| ### Runtime Variables (Execution-Time) | ||
|
|
||
| **✅ Correct Pattern:** | ||
| ```yaml | ||
| steps: | ||
| - pwsh: | | ||
| Write-Host "##vso[task.setvariable variable=MyVar]somevalue" | ||
| displayName: Set Variable | ||
|
|
||
| - task: SomeTask@1 | ||
| condition: eq(variables['MyVar'], 'somevalue') | ||
| ``` | ||
|
|
||
| ## Common Scenarios | ||
|
|
||
| ### Scenario 1: Check if Variable Equals Value | ||
|
|
||
| ```yaml | ||
| - task: DoSomething@1 | ||
| condition: eq(variables['PREVIEW'], 'true') | ||
| ``` | ||
|
|
||
| ### Scenario 2: Multiple Variable Conditions (OR) | ||
|
|
||
| ```yaml | ||
| - task: DoSomething@1 | ||
| condition: or(eq(variables['STABLE'], 'true'), eq(variables['LTS'], 'true')) | ||
| ``` | ||
|
|
||
| ### Scenario 3: Multiple Variable Conditions (AND) | ||
|
|
||
| ```yaml | ||
| - task: DoSomething@1 | ||
| condition: and(succeeded(), eq(variables['Architecture'], 'fxdependent')) | ||
| ``` | ||
|
|
||
| ### Scenario 4: Complex Conditions | ||
|
|
||
| ```yaml | ||
| - task: DoSomething@1 | ||
| condition: and( | ||
| succeededOrFailed(), | ||
| ne(variables['UseAzDevOpsFeed'], ''), | ||
| eq(variables['Build.SourceBranch'], 'refs/heads/master') | ||
| ) | ||
| ``` | ||
|
|
||
| ### Scenario 5: Built-in Variables | ||
|
|
||
| ```yaml | ||
| - task: CodeQL3000Init@0 | ||
| condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') | ||
|
|
||
| - step: finalize | ||
| condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues') | ||
| ``` | ||
|
|
||
| ### Scenario 6: Parameter vs Variable | ||
|
|
||
| ```yaml | ||
| parameters: | ||
| - name: OfficialBuild | ||
| type: boolean | ||
|
|
||
| steps: | ||
| # Parameter condition (compile-time) | ||
| - task: SignFiles@1 | ||
| condition: eq('${{ parameters.OfficialBuild }}', 'true') | ||
|
|
||
| # Variable condition (runtime) | ||
| - task: PublishArtifact@1 | ||
| condition: eq(variables['PUBLISH_ENABLED'], 'true') | ||
| ``` | ||
|
|
||
| ## Why This Matters | ||
|
|
||
| **String Expansion `$(VAR)` in Conditions:** | ||
| - When you use `'$(VAR)'` in a condition, Azure Pipelines attempts to expand it as a string | ||
| - If the variable is undefined or empty, it becomes an empty string `''` | ||
| - The condition `eq('', 'true')` will always be false | ||
| - This makes debugging difficult because there's no error message | ||
|
|
||
| **Variables Array Syntax `variables['VAR']`:** | ||
| - This is the proper way to reference runtime variables in conditions | ||
| - Azure Pipelines correctly evaluates the variable's value | ||
| - Undefined variables are handled properly by the condition evaluator | ||
| - This is the standard pattern used throughout Azure Pipelines | ||
|
|
||
| ## Reference Examples | ||
|
|
||
| Working examples can be found in: | ||
| - `.pipelines/templates/linux.yml` - Build.SourceBranch conditions | ||
| - `.pipelines/templates/windows-hosted-build.yml` - Architecture conditions | ||
| - `.pipelines/templates/compliance/apiscan.yml` - CODEQL_ENABLED conditions | ||
| - `.pipelines/templates/insert-nuget-config-azfeed.yml` - Complex AND/OR conditions | ||
|
TravisEz13 marked this conversation as resolved.
|
||
|
|
||
| ## Quick Reference Table | ||
|
|
||
| | Context | Syntax | Example | | ||
| |---------|--------|---------| | ||
| | Condition expression | `variables['Name']` | `condition: eq(variables['PREVIEW'], 'true')` | | ||
| | Script content | `$(Name)` | `pwsh: Write-Host "$(PREVIEW)"` | | ||
| | Task input | `$(Name)` | `inputs: path: '$(Build.SourcesDirectory)'` | | ||
| | Template parameter | `${{ parameters.Name }}` | `condition: eq('${{ parameters.Official }}', 'true')` | | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Condition Always False | ||
| If your condition is always evaluating to false: | ||
| 1. Check if you're using `'$(VAR)'` instead of `variables['VAR']` | ||
| 2. Verify the variable is actually set (add a debug step to print the variable) | ||
| 3. Check the variable value is exactly what you expect (case-sensitive) | ||
|
|
||
| ### Variable Not Found | ||
| If you get errors about variables not being found: | ||
| 1. Ensure the variable is set before the condition is evaluated | ||
| 2. Check that the variable name is spelled correctly | ||
| 3. Verify the variable is in scope (job vs. stage vs. pipeline level) | ||
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Always use `variables['Name']` in conditions** - This is the correct Azure Pipelines pattern | ||
| 2. **Use `$(Name)` for string expansion** in scripts and inputs | ||
| 3. **Use `${{ parameters.Name }}` for template parameters** (compile-time) | ||
| 4. **Add debug steps** to verify variable values when troubleshooting conditions | ||
| 5. **Follow existing patterns** in the repository - grep for `condition:` to see examples | ||
|
|
||
| ## Common Mistakes | ||
|
|
||
| ❌ **Mistake 1: String expansion in condition** | ||
| ```yaml | ||
| condition: eq('$(PREVIEW)', 'true') # WRONG | ||
| ``` | ||
|
|
||
| ✅ **Fix:** | ||
| ```yaml | ||
| condition: eq(variables['PREVIEW'], 'true') # CORRECT | ||
| ``` | ||
|
|
||
| ❌ **Mistake 2: Missing quotes around parameter** | ||
| ```yaml | ||
| condition: eq(${{ parameters.Official }}, true) # WRONG | ||
| ``` | ||
|
|
||
| ✅ **Fix:** | ||
| ```yaml | ||
| condition: eq('${{ parameters.Official }}', 'true') # CORRECT | ||
| ``` | ||
|
|
||
| ❌ **Mistake 3: Mixing syntax** | ||
| ```yaml | ||
| condition: or(eq('$(STABLE)', 'true'), eq(variables['LTS'], 'true')) # INCONSISTENT | ||
| ``` | ||
|
|
||
| ✅ **Fix:** | ||
| ```yaml | ||
| condition: or(eq(variables['STABLE'], 'true'), eq(variables['LTS'], 'true')) # CORRECT | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.

Uh oh!
There was an error while loading. Please reload this page.