1717# displayName: Setup Private Feeds Credentials
1818# inputs:
1919# filePath: $(Build.SourcesDirectory)/eng/common/SetupNugetSources.sh
20- # arguments: $BUILD_SOURCESDIRECTORY /NuGet.config $Token
20+ # arguments: $(Build.SourcesDirectory) /NuGet.config $Token
2121# condition: ne(variables['Agent.OS'], 'Windows_NT')
2222# env:
2323# Token: $(dn-bot-dnceng-artifact-feeds-rw)
@@ -42,7 +42,12 @@ scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
4242. " $scriptroot /tools.sh"
4343
4444if [ ! -f " $ConfigFile " ]; then
45- Write-PipelineTelemetryError -Category ' Build' -Message " Couldn't find the file NuGet config file: $ConfigFile "
45+ Write-PipelineTelemetryError -Category ' Build' " Error: Eng/common/SetupNugetSources.sh returned a non-zero exit code. Couldn't find the NuGet config file: $ConfigFile "
46+ ExitWithExitCode 1
47+ fi
48+
49+ if [ -z " $CredToken " ]; then
50+ Write-PipelineTelemetryError -category ' Build' " Error: Eng/common/SetupNugetSources.sh returned a non-zero exit code. Please supply a valid PAT"
4651 ExitWithExitCode 1
4752fi
4853
@@ -52,7 +57,7 @@ if [[ `uname -s` == "Darwin" ]]; then
5257fi
5358
5459# Ensure there is a <packageSources>...</packageSources> section.
55- grep -i " <packageSources>" $ConfigFile
60+ grep -i " <packageSources>" $ConfigFile
5661if [ " $? " != " 0" ]; then
5762 echo " Adding <packageSources>...</packageSources> section."
5863 ConfigNodeHeader=" <configuration>"
@@ -62,7 +67,7 @@ if [ "$?" != "0" ]; then
6267fi
6368
6469# Ensure there is a <packageSourceCredentials>...</packageSourceCredentials> section.
65- grep -i " <packageSourceCredentials>" $ConfigFile
70+ grep -i " <packageSourceCredentials>" $ConfigFile
6671if [ " $? " != " 0" ]; then
6772 echo " Adding <packageSourceCredentials>...</packageSourceCredentials> section."
6873
@@ -72,37 +77,64 @@ if [ "$?" != "0" ]; then
7277 sed -i.bak " s|$PackageSourcesNodeFooter |$PackageSourcesNodeFooter ${NL} $PackageSourceCredentialsTemplate |" NuGet.config
7378fi
7479
75- # Ensure dotnet3-internal and dotnet3-internal-transport is in the packageSources
76- grep -i " <add key=\" dotnet3-internal\" >" $ConfigFile
77- if [ " $? " != " 0" ]; then
78- echo " Adding dotnet3-internal to the packageSources."
80+ PackageSources=()
7981
80- PackageSourcesNodeFooter=" </packageSources>"
81- PackageSourceTemplate=" ${TB} <add key=\" dotnet3-internal\" value=\" https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3-internal/nuget/v2\" />"
82+ # Ensure dotnet3-internal and dotnet3-internal-transport are in the packageSources if the public dotnet3 feeds are present
83+ grep -i " <add key=\" dotnet3\" " $ConfigFile
84+
85+ if [ " $? " == " 0" ]; then
86+ grep -i " <add key=\" dotnet3-internal\" >" $ConfigFile
87+ if [ " $? " != " 0" ]; then
88+ echo " Adding dotnet3-internal to the packageSources."
89+ PackageSourcesNodeFooter=" </packageSources>"
90+ PackageSourceTemplate=" ${TB} <add key=\" dotnet3-internal\" value=\" https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3-internal/nuget/v2\" />"
91+
92+ sed -i.bak " s|$PackageSourcesNodeFooter |$PackageSourceTemplate ${NL} $PackageSourcesNodeFooter |" $ConfigFile
93+ fi
94+ PackageSources+=(' dotnet3-internal' )
95+
96+ grep -i " <add key=\" dotnet3-internal-transport\" " $ConfigFile
97+ if [ " $? " != " 0" ]; then
98+ echo " Adding dotnet3-internal-transport to the packageSources."
99+ PackageSourcesNodeFooter=" </packageSources>"
100+ PackageSourceTemplate=" ${TB} <add key=\" dotnet3-internal-transport\" value=\" https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3-internal-transport/nuget/v2\" />"
82101
83- sed -i.bak " s|$PackageSourcesNodeFooter |$PackageSourceTemplate ${NL} $PackageSourcesNodeFooter |" NuGet.config
102+ sed -i.bak " s|$PackageSourcesNodeFooter |$PackageSourceTemplate ${NL} $PackageSourcesNodeFooter |" $ConfigFile
103+ fi
104+ PackageSources+=(' dotnet3-internal-transport' )
84105fi
85106
86- # Ensure dotnet3-internal and dotnet3-internal-transport is in the packageSources
87- grep -i " <add key=\" dotnet3-internal-transport\" >" $ConfigFile
88- if [ " $? " != " 0" ]; then
89- echo " Adding dotnet3-internal-transport to the packageSources."
107+ # Ensure dotnet3.1-internal and dotnet3.1-internal-transport are in the packageSources if the public dotnet3.1 feeds are present
108+ grep -i " <add key=\" dotnet3.1\" " $ConfigFile
109+ if [ " $? " == " 0" ]; then
110+ grep -i " <add key=\" dotnet3.1-internal\" " $ConfigFile
111+ if [ " $? " != " 0" ]; then
112+ echo " Adding dotnet3.1-internal to the packageSources."
113+ PackageSourcesNodeFooter=" </packageSources>"
114+ PackageSourceTemplate=" ${TB} <add key=\" dotnet3.1-internal\" value=\" https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3.1-internal/nuget/v2\" />"
90115
91- PackageSourcesNodeFooter=" </packageSources>"
92- PackageSourceTemplate=" ${TB} <add key=\" dotnet3-internal-transport\" value=\" https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3-internal-transport/nuget/v2\" />"
116+ sed -i.bak " s|$PackageSourcesNodeFooter |$PackageSourceTemplate ${NL} $PackageSourcesNodeFooter |" $ConfigFile
117+ fi
118+ PackageSources+=(' dotnet3.1-internal' )
119+
120+ grep -i " <add key=\" dotnet3.1-internal-transport\" >" $ConfigFile
121+ if [ " $? " != " 0" ]; then
122+ echo " Adding dotnet3.1-internal-transport to the packageSources."
123+ PackageSourcesNodeFooter=" </packageSources>"
124+ PackageSourceTemplate=" ${TB} <add key=\" dotnet3.1-internal-transport\" value=\" https://pkgs.dev.azure.com/dnceng/_packaging/dotnet3.1-internal-transport/nuget/v2\" />"
93125
94- sed -i.bak " s|$PackageSourcesNodeFooter |$PackageSourceTemplate ${NL} $PackageSourcesNodeFooter |" NuGet.config
126+ sed -i.bak " s|$PackageSourcesNodeFooter |$PackageSourceTemplate ${NL} $PackageSourcesNodeFooter |" $ConfigFile
127+ fi
128+ PackageSources+=(' dotnet3.1-internal-transport' )
95129fi
96130
97131# I want things split line by line
98132PrevIFS=$IFS
99133IFS=$' \n '
100- PackageSources=$( grep -oh ' "darc-int-[^"]*"' $ConfigFile | tr -d ' "' )
134+ PackageSources+=" $IFS "
135+ PackageSources+=$( grep -oh ' "darc-int-[^"]*"' $ConfigFile | tr -d ' "' )
101136IFS=$PrevIFS
102137
103- PackageSources+=(' dotnet3-internal' )
104- PackageSources+=(' dotnet3-internal-transport' )
105-
106138for FeedName in ${PackageSources[@]} ; do
107139 # Check if there is no existing credential for this FeedName
108140 grep -i " <$FeedName >" $ConfigFile
@@ -112,6 +144,6 @@ for FeedName in ${PackageSources[@]} ; do
112144 PackageSourceCredentialsNodeFooter=" </packageSourceCredentials>"
113145 NewCredential=" ${TB}${TB} <$FeedName >${NL} <add key=\" Username\" value=\" dn-bot\" />${NL} <add key=\" ClearTextPassword\" value=\" $CredToken \" />${NL} </$FeedName >"
114146
115- sed -i.bak " s|$PackageSourceCredentialsNodeFooter |$NewCredential ${NL} $PackageSourceCredentialsNodeFooter |" NuGet.config
147+ sed -i.bak " s|$PackageSourceCredentialsNodeFooter |$NewCredential ${NL} $PackageSourceCredentialsNodeFooter |" $ConfigFile
116148 fi
117149done
0 commit comments