Copilot instructions
.github/instructions/onebranch-condition-syntax.instructions.mdCopilot instructions
Quality
73/100
Scores the file, not the repository.Length
734 words
26 headings · 18 code blocksRepository
55k
— · pushed 2 days agoLast changed
3 days ago
First indexed 3 days ago.12345# OneBranch Pipeline Condition Syntax67## Overview8Azure 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.910## Variable Reference Patterns1112### In Condition Expressions1314**✅ Correct Pattern:**15```yaml16condition: eq(variables['VariableName'], 'value')17condition: or(eq(variables['VAR1'], 'true'), eq(variables['VAR2'], 'true'))18condition: and(succeeded(), eq(variables['Architecture'], 'fxdependent'))19```2021**❌ Incorrect Patterns:**22```yaml23# Don't use $(VAR) string expansion in conditions24condition: eq('$(VariableName)', 'value')2526# Don't use direct variable references27condition: eq($VariableName, 'value')28```2930### In Script Content (pwsh, bash, etc.)3132**✅ Correct Pattern:**33```yaml34- pwsh: |35 $value = '$(VariableName)'36 Write-Host "Value: $(VariableName)"37```3839### In Input Fields4041**✅ Correct Pattern:**42```yaml43inputs:44 serviceEndpoint: '$(ServiceEndpoint)'45 sbConfigPath: '$(SBConfigPath)'46```4748## Parameter References4950### Template Parameters (Compile-Time)5152**✅ Correct Pattern:**53```yaml54parameters:55 - name: OfficialBuild56 type: boolean57 default: false5859steps:60 - task: SomeTask@161 condition: eq('${{ parameters.OfficialBuild }}', 'true')62```6364Note: Parameters use `${{ parameters.Name }}` because they're evaluated at template compile-time.6566### Runtime Variables (Execution-Time)6768**✅ Correct Pattern:**69```yaml70steps:71 - pwsh: |72 Write-Host "##vso[task.setvariable variable=MyVar]somevalue"73 displayName: Set Variable7475 - task: SomeTask@176 condition: eq(variables['MyVar'], 'somevalue')77```7879## Common Scenarios8081### Scenario 1: Check if Variable Equals Value8283```yaml84- task: DoSomething@185 condition: eq(variables['PREVIEW'], 'true')86```8788### Scenario 2: Multiple Variable Conditions (OR)8990```yaml91- task: DoSomething@192 condition: or(eq(variables['STABLE'], 'true'), eq(variables['LTS'], 'true'))93```9495### Scenario 3: Multiple Variable Conditions (AND)9697```yaml98- task: DoSomething@199 condition: and(succeeded(), eq(variables['Architecture'], 'fxdependent'))100```101102### Scenario 4: Complex Conditions103104```yaml105- task: DoSomething@1106 condition: and(107 succeededOrFailed(),108 ne(variables['UseAzDevOpsFeed'], ''),109 eq(variables['Build.SourceBranch'], 'refs/heads/master')110 )111```112113### Scenario 5: Built-in Variables114115```yaml116- task: CodeQL3000Init@0117 condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')118119- step: finalize120 condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues')121```122123### Scenario 6: Parameter vs Variable124125```yaml126parameters:127 - name: OfficialBuild128 type: boolean129130steps:131 # Parameter condition (compile-time)132 - task: SignFiles@1133 condition: eq('${{ parameters.OfficialBuild }}', 'true')134135 # Variable condition (runtime)136 - task: PublishArtifact@1137 condition: eq(variables['PUBLISH_ENABLED'], 'true')138```139140## Why This Matters141142**String Expansion `$(VAR)` in Conditions:**143- When you use `'$(VAR)'` in a condition, Azure Pipelines attempts to expand it as a string144- If the variable is undefined or empty, it becomes an empty string `''`145- The condition `eq('', 'true')` will always be false146- This makes debugging difficult because there's no error message147148**Variables Array Syntax `variables['VAR']`:**149- This is the proper way to reference runtime variables in conditions150- Azure Pipelines correctly evaluates the variable's value151- Undefined variables are handled properly by the condition evaluator152- This is the standard pattern used throughout Azure Pipelines153154## Reference Examples155156Working examples can be found in:157- `.pipelines/templates/linux.yml` - Build.SourceBranch conditions158- `.pipelines/templates/windows-hosted-build.yml` - Architecture conditions159- `.pipelines/templates/compliance/apiscan.yml` - CODEQL_ENABLED conditions160- `.pipelines/templates/insert-nuget-config-azfeed.yml` - Complex AND/OR conditions161162## Quick Reference Table163164| Context | Syntax | Example |165|---------|--------|---------|166| Condition expression | `variables['Name']` | `condition: eq(variables['PREVIEW'], 'true')` |167| Script content | `$(Name)` | `pwsh: Write-Host "$(PREVIEW)"` |168| Task input | `$(Name)` | `inputs: path: '$(Build.SourcesDirectory)'` |169| Template parameter | `${{ parameters.Name }}` | `condition: eq('${{ parameters.Official }}', 'true')` |170171## Troubleshooting172173### Condition Always False174If your condition is always evaluating to false:1751. Check if you're using `'$(VAR)'` instead of `variables['VAR']`1762. Verify the variable is actually set (add a debug step to print the variable)1773. Check the variable value is exactly what you expect (case-sensitive)178179### Variable Not Found180If you get errors about variables not being found:1811. Ensure the variable is set before the condition is evaluated1822. Check that the variable name is spelled correctly1833. Verify the variable is in scope (job vs. stage vs. pipeline level)184185## Best Practices1861871. **Always use `variables['Name']` in conditions** - This is the correct Azure Pipelines pattern1882. **Use `$(Name)` for string expansion** in scripts and inputs1893. **Use `${{ parameters.Name }}` for template parameters** (compile-time)1904. **Add debug steps** to verify variable values when troubleshooting conditions1915. **Follow existing patterns** in the repository - grep for `condition:` to see examples192193## Common Mistakes194195❌ **Mistake 1: String expansion in condition**196```yaml197condition: eq('$(PREVIEW)', 'true') # WRONG198```199200✅ **Fix:**201```yaml202condition: eq(variables['PREVIEW'], 'true') # CORRECT203```204205❌ **Mistake 2: Missing quotes around parameter**206```yaml207condition: eq(${{ parameters.Official }}, true) # WRONG208```209210✅ **Fix:**211```yaml212condition: eq('${{ parameters.Official }}', 'true') # CORRECT213```214215❌ **Mistake 3: Mixing syntax**216```yaml217condition: or(eq('$(STABLE)', 'true'), eq(variables['LTS'], 'true')) # INCONSISTENT218```219220✅ **Fix:**221```yaml222condition: or(eq(variables['STABLE'], 'true'), eq(variables['LTS'], 'true')) # CORRECT223```224
Also in PowerShell/PowerShell
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| PowerShell/PowerShell.github/instructions/build-and-packaging-steps.instructions.md · 55k | Copilot instructions | buildagent-behaviour | 58/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/build-checkout-prerequisites.instructions.md · 55k | Copilot instructions | setupbuildstylearch+1 | 81/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/build-configuration-guide.instructions.md · 55k | Copilot instructions | buildteststyletesting-strategy+2 | 74/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/code-review-branch-strategy.instructions.md · 55k | Copilot instructions | lint-formatstyletypesgit+1 | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/instruction-file-format.instructions.md · 55k | Copilot instructions | buildlint-formatstylearch+3 | 76/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/log-grouping-guidelines.instructions.md · 55k | Copilot instructions | buildtestdo-not | 77/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/onebranch-restore-phase-pattern.instructions.md · 55k | Copilot instructions | arch | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/onebranch-signing-configuration.instructions.md · 55k | Copilot instructions | buildstyledeployment | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/pester-set-itresult-pattern.instructions.md · 55k | Copilot instructions | setupstylearch | 62/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/pester-test-status-and-working-meaning.instructions.md · 55k | Copilot instructions | teststyle | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/powershell-automatic-variables.instructions.md · 55k | Copilot instructions | stylearchgitdeployment+1 | 69/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/powershell-module-organization.instructions.md · 55k | Copilot instructions | buildteststylearch+2 | 69/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/powershell-parameter-naming.instructions.md · 55k | Copilot instructions | styledo-not | 65/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/publishing-pester-result.instructions.md · 55k | Copilot instructions | testlint-formatstylearch+3 | 69/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/script-module-file-format.instructions.md · 55k | Copilot instructions | lint-format | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/start-native-execution.instructions.md · 55k | Copilot instructions | buildstylearchgit+1 | 86/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/start-psbuild-basics.instructions.md · 55k | Copilot instructions | buildtesting-strategydeploymentagent-behaviour | 54/100 | 3 days ago | |
| PowerShell/PowerShell.github/instructions/troubleshooting-builds.instructions.md · 55k | Copilot instructions | buildgitdeployment | 54/100 | 3 days ago |
Diff against .github/instructions/build-and-packaging-steps.instructions.md Diff against .github/instructions/build-checkout-prerequisites.instructions.md Diff against .github/instructions/build-configuration-guide.instructions.md Diff against .github/instructions/code-review-branch-strategy.instructions.md Diff against .github/instructions/instruction-file-format.instructions.md Diff against .github/instructions/log-grouping-guidelines.instructions.md Diff against .github/instructions/onebranch-restore-phase-pattern.instructions.md Diff against .github/instructions/onebranch-signing-configuration.instructions.md Diff against .github/instructions/pester-set-itresult-pattern.instructions.md Diff against .github/instructions/pester-test-status-and-working-meaning.instructions.md Diff against .github/instructions/powershell-automatic-variables.instructions.md Diff against .github/instructions/powershell-module-organization.instructions.md Diff against .github/instructions/powershell-parameter-naming.instructions.md Diff against .github/instructions/publishing-pester-result.instructions.md Diff against .github/instructions/script-module-file-format.instructions.md Diff against .github/instructions/start-native-execution.instructions.md Diff against .github/instructions/start-psbuild-basics.instructions.md Diff against .github/instructions/troubleshooting-builds.instructions.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| pytorch/pytorch.github/copilot-instructions.md · 102k | Copilot instructions | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| chihebnabil/lovable-boilerplate.github/instructions/global.instructions.md · 63 | Copilot instructions | buildlint-formatstylearch+4 | 100/100 | 3 days ago | |
| louislam/uptime-kuma.github/copilot-instructions.md · 90k | Copilot instructions | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| dotnet/roslyn.github/instructions/Compiler.instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 99/100 | 3 days ago | |
| hiyouga/LlamaFactory.github/copilot-instructions.md · 74k | Copilot instructions | setupbuildtestlint-format+5 | 97/100 | 2 days ago | |
| JCodesMore/ai-website-cloner-template.github/copilot-instructions.md · 31k | Copilot instructions | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| rtk-ai/rtk.github/copilot-instructions.md · 74k | Copilot instructions | buildtestlint-formatstyle+2 | 97/100 | 3 days ago | |
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 97/100 | 3 days ago |
