Skip to content

Commit 90a4b1c

Browse files
authored
Merge pull request #2564 from microsoft/dpaul-PipelineUpdate
Route pipeline package installs through Azure Artifacts feed
2 parents df3dc59 + 1a205d0 commit 90a4b1c

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

.build/Load-Module.ps1

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
# cspell:ignore accesstoken
5+
46
function Load-Module {
57
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseApprovedVerbs', '', Justification = 'Prefer verb usage')]
8+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'The token is provided at runtime via the pipeline SYSTEM_ACCESSTOKEN environment variable, not a hardcoded secret. A PSCredential is required to authenticate Install-Module against the Azure Artifacts feed.')]
69
[CmdletBinding()]
710
[OutputType([bool])]
811
param (
@@ -39,15 +42,40 @@ function Load-Module {
3942
}
4043

4144
$params = @{
42-
Name = $Name
45+
Name = $Name
46+
Force = $true
4347
}
4448

4549
if (-not [string]::IsNullOrEmpty($MinimumVersion)) {
4650
$params.MinimumVersion = $MinimumVersion
4751
}
4852

53+
# Under Network Isolation the public PowerShell Gallery is blocked, so install
54+
# modules from the internal Azure Artifacts feed. These environment variables are
55+
# only set by the pipeline; local development continues to use the PowerShell Gallery.
56+
if (-not [string]::IsNullOrEmpty($env:CFS_FEED_SOURCE) -and
57+
-not [string]::IsNullOrEmpty($env:SYSTEM_ACCESSTOKEN)) {
58+
$repositoryName = "CssExchangeCfs"
59+
$secureToken = ConvertTo-SecureString $env:SYSTEM_ACCESSTOKEN -AsPlainText -Force
60+
$credential = [PSCredential]::new("azdo", $secureToken)
61+
62+
# Register the feed if it is missing, otherwise normalize it in case a reused
63+
# agent left it pointing at a different location or not trusted. Install-Module
64+
# is pinned to this repository below, so the public PowerShell Gallery does not
65+
# need to be unregistered.
66+
$existingRepository = Get-PSRepository -Name $repositoryName -ErrorAction SilentlyContinue
67+
if ($null -eq $existingRepository) {
68+
Register-PSRepository -Name $repositoryName -SourceLocation $env:CFS_FEED_SOURCE -InstallationPolicy Trusted -Credential $credential
69+
} elseif ($existingRepository.SourceLocation -ne $env:CFS_FEED_SOURCE -or $existingRepository.InstallationPolicy -ne "Trusted") {
70+
Set-PSRepository -Name $repositoryName -SourceLocation $env:CFS_FEED_SOURCE -InstallationPolicy Trusted -Credential $credential
71+
}
72+
73+
$params.Repository = $repositoryName
74+
$params.Credential = $credential
75+
}
76+
4977
$errorCount = $Error.Count
50-
Install-Module @params -Force
78+
Install-Module @params
5179
if ($Error.Count -gt $errorCount) {
5280
return $false
5381
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
dist
22
.DS_Store
33

4+
# Generated at pipeline runtime by "Configure CFS npm feed" (see azure-pipeline-merge.yml)
5+
.build/.npmrc
6+
47
# Personal Copilot/AI overrides (per-developer, not shared)
58
.copilot/
69
.claude/

azure-pipeline-merge.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extends:
99
parameters:
1010
settings:
1111
skipBuildTagsForGitHubPullRequests: true
12+
networkIsolationPolicy: Okay,CFSClean,CFSClean2
1213
pool:
1314
name: MSSecurity-1ES-Build-Agents-Pool
1415
image: MSSecurity-1ES-Windows-2022
@@ -19,7 +20,20 @@ extends:
1920
- stage: stage
2021
jobs:
2122
- job: job
23+
variables:
24+
CFS_FEED_SOURCE: 'https://pkgs.dev.azure.com/CSS-Exchange-Tools/$(System.TeamProjectId)/_packaging/$(CfsFeedName)/nuget/v2'
25+
NPM_CONFIG_GLOBALCONFIG: '$(Build.SourcesDirectory)/.build/.npmrc'
2226
steps:
27+
- pwsh: |
28+
$registry = "https://pkgs.dev.azure.com/CSS-Exchange-Tools/$(System.TeamProjectId)/_packaging/$(CfsFeedName)/npm/registry/"
29+
Set-Content -Path "$(Build.SourcesDirectory)/.build/.npmrc" -Value @("registry=$registry", "always-auth=true")
30+
displayName: "Configure CFS npm feed"
31+
- task: NuGetAuthenticate@1
32+
displayName: "Authenticate Azure Artifacts feed (PowerShell modules)"
33+
- task: npmAuthenticate@0
34+
displayName: "Authenticate Azure Artifacts feed (cspell)"
35+
inputs:
36+
workingFile: '$(Build.SourcesDirectory)/.build/.npmrc'
2337
- pwsh: |
2438
cd .\.build
2539
.\docs.ps1
@@ -35,6 +49,7 @@ extends:
3549
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/release'))
3650
env:
3751
TargetBranchName: $(System.PullRequest.TargetBranch)
52+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
3853
- pwsh: |
3954
cd .\.build
4055
.\Build.ps1
@@ -45,6 +60,7 @@ extends:
4560
displayName: "Running Invoke-Pester"
4661
env:
4762
TargetBranchName: $(System.PullRequest.TargetBranch)
63+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
4864
- pwsh: |
4965
cd .\.build
5066
.\ValidateMerge.ps1 -Branch $env:TargetBranchName

0 commit comments

Comments
 (0)