MegaBites-AI/Windows-powershell
0372
1---2applyTo: ".pipelines/**/*.{yml,yaml}"3---4 5# OneBranch Restore Phase Pattern6 7## Overview8When steps need to run in the OneBranch restore phase (before the main build phase), the `ob_restore_phase` environment variable must be set in the `env:` block of **each individual step**.9 10## Pattern11 12### ✅ Correct (Working Pattern)13```yaml14parameters:15- name: "ob_restore_phase"16 type: boolean17 default: true # or false if you don't want restore phase18 19steps:20- powershell: |21 # script content22 displayName: 'Step Name'23 env:24 ob_restore_phase: ${{ parameters.ob_restore_phase }}25```26 27The key is to:281. Define `ob_restore_phase` as a **boolean** parameter292. Set `ob_restore_phase: ${{ parameters.ob_restore_phase }}` directly in each step's `env:` block303. Pass `true` to run in restore phase, `false` to run in normal build phase31 32### ❌ Incorrect (Does Not Work)33```yaml34steps:35- powershell: |36 # script content37 displayName: 'Step Name'38 ${{ if eq(parameters.useRestorePhase, 'yes') }}:39 env:40 ob_restore_phase: true41```42 43Using conditionals at the same indentation level as `env:` causes only the first step to execute in restore phase.44 45## Parameters46 47Templates using this pattern should accept an `ob_restore_phase` boolean parameter:48 49```yaml50parameters:51- name: "ob_restore_phase"52 type: boolean53 default: true # Set to true to run in restore phase by default54```55 56## Reference Examples57 58Working examples of this pattern can be found in:59- `.pipelines/templates/insert-nuget-config-azfeed.yml` - Demonstrates the correct pattern60- `.pipelines/templates/SetVersionVariables.yml` - Updated to use this pattern61 62## Why This Matters63 64The restore phase in OneBranch pipelines runs before signing and other build operations. Steps that need to:65- Set environment variables for the entire build66- Configure authentication67- Prepare the repository structure68 69Must run in the restore phase to be available when subsequent stages execute.70 71## Common Use Cases72 73- Setting `REPOROOT` variable74- Configuring NuGet feeds with authentication75- Setting version variables76- Repository preparation and validation77 78## Troubleshooting79 80If only the first step in your template is running in restore phase:811. Check that `env:` block exists for **each step**822. Verify the conditional `${{ if ... }}:` is **inside** the `env:` block833. Confirm indentation is correct (conditional is indented under `env:`)84 