-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Azure Artifact authenticated feeds
- Loading branch information
Showing
10 changed files
with
169 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,13 @@ | ||
if ($env:AGENT_TOOLSDIRECTORY) { | ||
$path = "$env:AGENT_TOOLSDIRECTORY\vs-platform\tools" | ||
} elseif ($env:localappdata) { | ||
$path = "$env:localappdata\vs-platform\tools" | ||
} else { | ||
$path = "$PSScriptRoot\..\obj\tools" | ||
} | ||
|
||
if (!(Test-Path $path)) { | ||
New-Item -ItemType Directory -Path $Path | Out-Null | ||
} | ||
|
||
(Resolve-Path $path).Path |
This file contains 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,39 @@ | ||
<# | ||
.SYNOPSIS | ||
Set environment variables in the environment. | ||
Azure Pipeline and CMD environments are considered. | ||
.PARAMETER Variables | ||
A hashtable of variables to be set. | ||
.OUTPUTS | ||
A boolean indicating whether the environment variables can be expected to propagate to the caller's environment. | ||
#> | ||
[CmdletBinding(SupportsShouldProcess=$true)] | ||
Param( | ||
[Parameter(Mandatory=$true, Position=1)] | ||
$Variables | ||
) | ||
|
||
if ($Variables.Count -eq 0) { | ||
return $true | ||
} | ||
|
||
$cmdInstructions = !$env:TF_BUILD -and $env:PS1UnderCmd -eq '1' | ||
if ($cmdInstructions) { | ||
Write-Warning "Environment variables have been set that will be lost because you're running under cmd.exe" | ||
Write-Host "Environment variables that must be set manually:" -ForegroundColor Blue | ||
} | ||
|
||
$Variables.GetEnumerator() |% { | ||
Set-Item -Path env:$($_.Key) -Value $_.Value | ||
|
||
# If we're running in Azure Pipelines, set these environment variables | ||
if ($env:TF_BUILD) { | ||
Write-Host "##vso[task.setvariable variable=$($_.Key);]$($_.Value)" | ||
} | ||
|
||
if ($cmdInstructions) { | ||
Write-Host "SET $($_.Key)=$($_.Value)" | ||
} | ||
} | ||
|
||
return !$cmdInstructions |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,62 @@ | ||
<# | ||
.SYNOPSIS | ||
Downloads and installs the Microsoft Artifacts Credential Provider | ||
from https://github.com/microsoft/artifacts-credprovider | ||
to assist in authenticating to Azure Artifact feeds in interactive development | ||
or unattended build agents. | ||
.PARAMETER AccessToken | ||
An optional access token for authenticating to Azure Artifacts authenticated feeds. | ||
#> | ||
[CmdletBinding()] | ||
Param ( | ||
[Parameter()] | ||
[string]$AccessToken | ||
) | ||
|
||
$toolsPath = & "$PSScriptRoot\..\azure-pipelines\Get-TempToolsPath.ps1" | ||
|
||
if ($IsMacOS -or $IsLinux) { | ||
$installerScript = "installcredprovider.sh" | ||
$sourceUrl = "https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh" | ||
} else { | ||
$installerScript = "installcredprovider.ps1" | ||
$sourceUrl = "https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1" | ||
} | ||
|
||
$installerScript = Join-Path $toolsPath $installerScript | ||
|
||
if (!(Test-Path $installerScript)) { | ||
Invoke-WebRequest $sourceUrl -OutFile $installerScript | ||
} | ||
|
||
$installerScript = (Resolve-Path $installerScript).Path | ||
|
||
if ($IsMacOS -or $IsLinux) { | ||
chmod u+x $installerScript | ||
} | ||
|
||
& $installerScript | ||
|
||
if ($AccessToken) { | ||
$endpoints = @() | ||
|
||
$nugetConfig = [xml](Get-Content -Path "$PSScriptRoot\..\nuget.config") | ||
|
||
$nugetConfig.configuration.packageSources.add |? { $_.value -match '^https://pkgs\.dev\.azure\.com/' } |% { | ||
$endpoint = New-Object -TypeName PSObject | ||
Add-Member -InputObject $endpoint -MemberType NoteProperty -Name endpoint -Value $_.value | ||
Add-Member -InputObject $endpoint -MemberType NoteProperty -Name username -Value ado | ||
Add-Member -InputObject $endpoint -MemberType NoteProperty -Name password -Value $AccessToken | ||
$endpoints += $endpoint | ||
} | ||
|
||
$auth = New-Object -TypeName PSObject | ||
Add-Member -InputObject $auth -MemberType NoteProperty -Name endpointCredentials -Value $endpoints | ||
|
||
$authJson = ConvertTo-Json -InputObject $auth | ||
$envVars = @{ | ||
'VSS_NUGET_EXTERNAL_FEED_ENDPOINTS'=$authJson; | ||
} | ||
|
||
& "$PSScriptRoot\..\azure-pipelines\Set-EnvVars.ps1" -Variables $envVars | Out-Null | ||
} |