5 # Sets VSS_NUGET_EXTERNAL_FEED_ENDPOINTS based on the "darc-int-*" feeds defined in NuGet.config. This is needed
6 # in build agents by CredProvider to authenticate the restore requests to internal feeds as specified in
7 # https://github.com/microsoft/artifacts-credprovider/blob/0f53327cd12fd893d8627d7b08a2171bf5852a41/README.md#environment-variables.
8 # This should ONLY be called from identified internal builds
9 function SetupCredProvider
{
12 # Install the Cred Provider NuGet plugin
13 echo "Setting up Cred Provider NuGet plugin in the agent..."...
14 echo "Getting 'installcredprovider.ps1' from 'https://github.com/microsoft/artifacts-credprovider'..."
16 local url
="https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh"
18 echo "Writing the contents of 'installcredprovider.ps1' locally..."
19 local installcredproviderPath
="installcredprovider.sh"
20 if command -v curl
> /dev
/null
; then
21 curl
$url > "$installcredproviderPath"
23 wget
-q -O "$installcredproviderPath" "$url"
26 echo "Installing plugin..."
27 .
"$installcredproviderPath"
29 echo "Deleting local copy of 'installcredprovider.sh'..."
30 rm installcredprovider.sh
32 if [ ! -d "$HOME/.nuget/plugins" ]; then
33 Write-PipelineTelemetryError
-category 'Build' 'CredProvider plugin was not installed correctly!'
36 echo "CredProvider plugin was installed correctly!"
39 # Then, we set the 'VSS_NUGET_EXTERNAL_FEED_ENDPOINTS' environment variable to restore from the stable
42 local nugetConfigPath
="$repo_root/NuGet.config"
44 if [ ! "$nugetConfigPath" ]; then
45 Write-PipelineTelemetryError
-category 'Build' "NuGet.config file not found in repo's root!"
50 local nugetConfigPackageValues
=`cat "$nugetConfigPath" | grep "key=\"darc-int-"`
51 local pattern
="value=\"(.*)\""
53 for value
in $nugetConfigPackageValues
55 if [[ $value =~
$pattern ]]; then
56 local endpoint
="${BASH_REMATCH[1]}"
57 endpoints
+="{\"endpoint\": \"$endpoint\", \"password\": \"$authToken\"},"
61 endpoints
=${endpoints%?}
64 if [ ${#endpoints} -gt 2 ]; then
65 # Create the JSON object. It should look like '{"endpointCredentials": [{"endpoint":"http://example.index.json", "username":"optional", "password":"accesstoken"}]}'
66 local endpointCredentials
="{\"endpointCredentials\": "$endpoints"}"
68 echo "##vso[task.setvariable variable=VSS_NUGET_EXTERNAL_FEED_ENDPOINTS]$endpointCredentials"
69 echo "##vso[task.setvariable variable=NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED]False"
71 echo "No internal endpoints found in NuGet.config"
75 # Workaround for https://github.com/microsoft/msbuild/issues/4430
76 function InstallDotNetSdkAndRestoreArcade
{
77 local dotnetTempDir
="$repo_root/dotnet"
78 local dotnetSdkVersion
="2.1.507" # After experimentation we know this version works when restoring the SDK (compared to 3.0.*)
79 local restoreProjPath
="$repo_root/eng/common/restore.proj"
81 echo "Installing dotnet SDK version $dotnetSdkVersion to restore Arcade SDK..."
82 echo "<Project Sdk=\"Microsoft.DotNet.Arcade.Sdk\"/>" > "$restoreProjPath"
84 InstallDotNetSdk
"$dotnetTempDir" "$dotnetSdkVersion"
86 local res
=`$dotnetTempDir/dotnet restore $restoreProjPath`
87 echo "Arcade SDK restored!"
90 if [ "$restoreProjPath" ]; then
94 if [ "$dotnetTempDir" ]; then
99 source="${BASH_SOURCE[0]}"
104 while [[ $# > 0 ]]; do
105 opt
="$(echo "$1" | awk '{print tolower($0)}')"
116 echo "Invalid argument: $1"
125 while [[ -h "$source" ]]; do
126 scriptroot
="$( cd -P "$
( dirname "$source" )" && pwd )"
127 source="$(readlink "$source")"
128 # if $source was a relative symlink, we need to resolve it relative to the path where the
129 # symlink file was located
130 [[ $source != /* ]] && source="$scriptroot/$source"
132 scriptroot
="$( cd -P "$
( dirname "$source" )" && pwd )"
134 .
"$scriptroot/tools.sh"
136 if [ "$operation" = "setup" ]; then
137 SetupCredProvider
$authToken
138 elif [ "$operation" = "install-restore" ]; then
139 InstallDotNetSdkAndRestoreArcade
141 echo "Unknown operation '$operation'!"