@@ -128,23 +128,9 @@ foreach ($packageDetail in $packageDetails) {
128128 if ($packageReposityUrl -match " https://pkgs.dev.azure.com/azure-sdk/\b(internal|public)\b/*" ) {
129129 # Azure DevOps feeds don't support staging
130130 $shouldPublishPackage = $ShouldPublish -and ! $StageOnly
131- $releaseType = ' AzureDevOps'
132- }
133- elseif ($packageReposityUrl -like " https://oss.sonatype.org/service/local/staging/deploy/maven2/" ) {
134- if ($packageDetail.IsSnapshot ) {
135- # Snapshots don't go to the standard maven central url
136- $packageReposityUrl = " https://oss.sonatype.org/content/repositories/snapshots/"
137- $releaseType = ' MavenCentralSnapshot'
138- }
139- elseif ($StageOnly ) {
140- $releaseType = ' MavenCentralStaging'
141- }
142- else {
143- $releaseType = ' MavenCentral'
144- }
145131 }
146132 else {
147- throw " Repository URL must be either an Azure Artifacts feed, or a SonaType Nexus feed ."
133+ throw " Repository URL must be an Azure Artifacts feed, anything else must be published through ESRP ."
148134 }
149135
150136 # Local GPG deployment is required when we're not going to publish a package, or when we're publishing to maven central
@@ -161,6 +147,15 @@ foreach ($packageDetail in $packageDetails) {
161147 $gpgexeOption = " -Dgpgexe=$GPGExecutablePath "
162148 Write-Information " GPG Executable Option is: $gpgexeOption "
163149
150+ $gpgPluginVersion = . $PSScriptRoot \Get-ExternalDependencyVersion.ps1 - GroupId ' org.apache.maven.plugins' - ArtifactId ' maven-gpg-plugin'
151+ if ($LASTEXITCODE ) {
152+ Write-Information " ##vso[task.logissue type=error]Unable to resolve version of external dependency 'org.apache.maven.plugins:maven-gpg-plugin'"
153+ exit $LASTEXITCODE
154+ }
155+
156+ $gpgSignAndDeployWithVer = " org.apache.maven.plugins:maven-gpg-plugin:$gpgPluginVersion `:sign-and-deploy-file"
157+
158+
164159 if ($requiresLocalGpg ) {
165160 $localRepositoryDirectory = Get-RandomRepositoryDirectory
166161 $localRepositoryDirectoryUri = $ ([Uri ]$localRepositoryDirectory.FullName ).AbsoluteUri
@@ -170,8 +165,8 @@ foreach ($packageDetail in $packageDetails) {
170165 Write-Information " URL Option is: $urlOption "
171166
172167 Write-Information " Signing and deploying package to $localRepositoryDirectoryUri "
173- Write-Information " mvn gpg:sign-and-deploy-file `" --batch-mode`" `" $pomOption `" `" $fileOption `" `" $javadocOption `" `" $sourcesOption `" `" $filesOption `" $classifiersOption `" $typesOption `" `" $urlOption `" `" $gpgexeOption `" `" -DrepositoryId=target-repo`" `" --settings=$PSScriptRoot \..\maven.publish.settings.xml`" "
174- mvn gpg:sign - and - deploy-file " --batch-mode" " $pomOption " " $fileOption " " $javadocOption " " $sourcesOption " " $filesOption " $classifiersOption " $typesOption " " $urlOption " " $gpgexeOption " " -DrepositoryId=target-repo" " --settings=$PSScriptRoot \..\maven.publish.settings.xml"
168+ Write-Information " mvn $gpgSignAndDeployWithVer `" --batch-mode`" `" $pomOption `" `" $fileOption `" `" $javadocOption `" `" $sourcesOption `" `" $filesOption `" $classifiersOption `" $typesOption `" `" $urlOption `" `" $gpgexeOption `" `" -DrepositoryId=target-repo`" `" --settings=$PSScriptRoot \..\maven.publish.settings.xml`" "
169+ mvn $gpgSignAndDeployWithVer " --batch-mode" " $pomOption " " $fileOption " " $javadocOption " " $sourcesOption " " $filesOption " $classifiersOption " $typesOption " " $urlOption " " $gpgexeOption " " -DrepositoryId=target-repo" " --settings=$PSScriptRoot \..\maven.publish.settings.xml"
175170 if ($LASTEXITCODE ) { exit $LASTEXITCODE }
176171 }
177172
@@ -181,121 +176,23 @@ foreach ($packageDetail in $packageDetails) {
181176 continue
182177 }
183178
184- if ($releaseType -eq ' AzureDevOps' ) {
185- Write-Information " GPG Signing and deploying package in one step to devops feed: $packageReposityUrl "
186- Write-Information " mvn gpg:sign-and-deploy-file `" --batch-mode`" `" $pomOption `" `" $fileOption `" `" $javadocOption `" `" $sourcesOption `" `" $filesOption `" $classifiersOption `" $typesOption `" `" -Durl=$packageReposityUrl `" `" $gpgexeOption `" `" -DrepositoryId=target-repo`" `" -Drepo.password=[redacted]`" `" --settings=$PSScriptRoot \..\maven.publish.settings.xml`" "
187- mvn gpg:sign- and- deploy-file " --batch-mode" " $pomOption " " $fileOption " " $javadocOption " " $sourcesOption " " $filesOption " $classifiersOption " $typesOption " " -Durl=$packageReposityUrl " " $gpgexeOption " " -DrepositoryId=target-repo" " -Drepo.password=$RepositoryPassword " " --settings=$PSScriptRoot \..\maven.publish.settings.xml"
188-
189- if ($LASTEXITCODE -eq 0 ) {
190- Write-Information " Package $ ( $packageDetail.FullyQualifiedName ) deployed"
191- continue
192- }
193-
194- Write-Information " Release attempt $attemt exited with code $LASTEXITCODE "
195- Write-Information " Checking Azure DevOps to see if release was successful"
196- if (Test-ReleasedPackage - RepositoryUrl $packageReposityUrl - PackageDetail $packageDetail - BearerToken $RepositoryPassword ) {
197- Write-Information " Package $ ( $packageDetail.FullyQualifiedName ) deployed despite non-zero exit code."
198- continue
199- }
179+ Write-Information " GPG Signing and deploying package in one step to devops feed: $packageReposityUrl "
180+ Write-Information " mvn $gpgSignAndDeployWithVer `" --batch-mode`" `" $pomOption `" `" $fileOption `" `" $javadocOption `" `" $sourcesOption `" `" $filesOption `" $classifiersOption `" $typesOption `" `" -Durl=$packageReposityUrl `" `" $gpgexeOption `" `" -DrepositoryId=target-repo`" `" -Drepo.password=[redacted]`" `" --settings=$PSScriptRoot \..\maven.publish.settings.xml`" "
181+ mvn $gpgSignAndDeployWithVer " --batch-mode" " $pomOption " " $fileOption " " $javadocOption " " $sourcesOption " " $filesOption " $classifiersOption " $typesOption " " -Durl=$packageReposityUrl " " $gpgexeOption " " -DrepositoryId=target-repo" " -Drepo.password=$RepositoryPassword " " --settings=$PSScriptRoot \..\maven.publish.settings.xml"
200182
201- exit $LASTEXITCODE
202- }
203- elseif ($releaseType -eq ' MavenCentralSnapshot' ) {
204- Write-Information " GPG Signing and deploying package in one step to Sonatype snapshots: $packageReposityUrl "
205- Write-Information " mvn gpg:sign-and-deploy-file `" --batch-mode`" `" $pomOption `" `" $fileOption `" `" $javadocOption `" `" $sourcesOption `" `" $filesOption `" $classifiersOption `" $typesOption `" `" -Durl=$packageReposityUrl `" `" $gpgexeOption `" `" -DrepositoryId=target-repo`" `" -Drepo.username=`"`" $RepositoryUsername `"`"`" `" -Drepo.password=[redacted]`" `" --settings=$PSScriptRoot \..\maven.publish.settings.xml`" "
206- mvn gpg:sign- and- deploy-file " --batch-mode" " $pomOption " " $fileOption " " $javadocOption " " $sourcesOption " " $filesOption " $classifiersOption " $typesOption " " -Durl=$packageReposityUrl " " $gpgexeOption " " -DrepositoryId=target-repo" " -Drepo.username="" $RepositoryUsername "" " " -Drepo.password="" $RepositoryPassword "" " " --settings=$PSScriptRoot \..\maven.publish.settings.xml"
207- if ($LASTEXITCODE ) { exit $LASTEXITCODE }
183+ if ($LASTEXITCODE -eq 0 ) {
184+ Write-Information " Package $ ( $packageDetail.FullyQualifiedName ) deployed"
185+ continue
208186 }
209- else {
210-
211- $resultsTime = [diagnostics.stopwatch ]::StartNew()
212- # IsMavenPackageVersionPublished is a very quick check to see if the pom is on maven which takes about 1-2 seconds
213- # to complete. If the POM if there, Test-ReleasedPackage will look at all of the package artifacts (pom, jars, .md)
214- # and compare their hashes. The reason we need the quick check first, is that Test-ReleasedPackage, when called
215- # on something that hasn't been released, takes 90 seconds if none of the artifacts have been released and about
216- # 25 seconds, if they have. The first time an artifact is being released we use IsMavenPackageVersionPublished so
217- # we don't add 90 seconds on to every Maven release.
218- if (IsMavenPackageVersionPublished - pkgId $packageDetail.ArtifactID - pkgVersion $packageDetail.Version - groupId $packageDetail.GroupId ) {
219- if (Test-ReleasedPackage - RepositoryUrl $packageReposityUrl - PackageDetail $packageDetail ) {
220- Write-Information " Package $ ( $packageDetail.FullyQualifiedName ) has already been deployed."
221- continue
222- }
223- } else {
224- Write-Information " $ ( $packageDetail.FullyQualifiedName ) has not yet deployed."
225- }
226- Write-Information " Time to test released package=$ ( $resultstime.Elapsed.ToString (' dd\.hh\:mm\:ss' )) "
227-
228- # Maven Central Staging + optional Release
229- $repositoryDirectoryOption = " -DrepositoryDirectory=$localRepositoryDirectory "
230- Write-Information " Repository Directory Option is: $repositoryDirectoryOption "
231187
232- $stagingProfileIdOption = " -DstagingProfileId=$ ( $packageDetail.SonaTypeProfileID ) "
233- Write-Information " Staging Profile ID Option is: $stagingProfileIdOption "
234-
235- $stagingDescriptionOption = " -DstagingDescription=$ ( $packageDetail.FullyQualifiedName ) "
236- Write-Information " Staging Description Option is: $stagingDescriptionOption "
237-
238- $nexusPluginVersion = . $PSScriptRoot \Get-ExternalDependencyVersion.ps1 - GroupId ' org.sonatype.plugins' - ArtifactId ' nexus-staging-maven-plugin'
239- if ($LASTEXITCODE ) {
240- Write-Information " ##vso[task.logissue type=error]Unable to resolve version of external dependency 'org.sonatype.plugins:nexus-staging-maven-plugin'"
241- exit $LASTEXITCODE
242- }
243-
244- $stagingGoal = " org.sonatype.plugins:nexus-staging-maven-plugin:$nexusPluginVersion `:deploy-staged-repository"
245- $releaseGoal = " org.sonatype.plugins:nexus-staging-maven-plugin:$nexusPluginVersion `:rc-release"
246-
247- Write-Information " Staging package to Maven Central"
248- Write-Information " mvn $stagingGoal `" --batch-mode`" `" -DnexusUrl=https://oss.sonatype.org`" `" $repositoryDirectoryOption `" `" $stagingProfileIdOption `" `" $stagingDescriptionOption `" `" -DrepositoryId=target-repo`" `" -DserverId=target-repo`" `" -Drepo.username=$RepositoryUsername `" `" -Drepo.password=`" [redacted]`"`" `" --settings=$PSScriptRoot \..\maven.publish.settings.xml`" "
249- mvn $stagingGoal " --batch-mode" " -DnexusUrl=https://oss.sonatype.org" " $repositoryDirectoryOption " " $stagingProfileIdOption " " $stagingDescriptionOption " " -DrepositoryId=target-repo" " -DserverId=target-repo" " -Drepo.username=$RepositoryUsername " " -Drepo.password="" $RepositoryPassword "" " " --settings=$PSScriptRoot \..\maven.publish.settings.xml"
250-
251- if ($LASTEXITCODE ) {
252- Write-Information ' ##vso[task.logissue type=error]Staging to Maven Central failed. For troubleshooting, see https://aka.ms/azsdk/maven-central-tsg'
253- exit $LASTEXITCODE
254- }
255-
256- Write-Information " Reading staging properties."
257- $stagedRepositoryProperties = ConvertFrom-StringData (Get-Content " $localRepositoryDirectory \$ ( $packageDetail.SonaTypeProfileID ) .properties" - Raw)
258-
259- $stagedRepositoryId = $stagedRepositoryProperties [" stagingRepository.id" ]
260- Write-Information " Staging Repository ID is: $stagedRepositoryId "
261-
262- $stagedRepositoryUrl = $stagedRepositoryProperties [" stagingRepository.url" ]
263- Write-Information " Staging Repository URL is: $stagedRepositoryUrl "
264-
265- if ($releaseType -eq ' MavenCentralStaging' ) {
266- Write-Information " Skipping release of staging repository because Stage Only == true."
267- continue
268- }
269-
270- $attempt = 0
271- $success = $false ;
272-
273- while ($attempt ++ -lt 3 ) {
274- Write-Information " Releasing staging repostiory $stagedRepositoryId , attempt $attempt "
275- Write-Information " mvn $releaseGoal `" -DstagingRepositoryId=$stagedRepositoryId `" `" -DnexusUrl=https://oss.sonatype.org`" `" -DrepositoryId=target-repo`" `" -DserverId=target-repo`" `" -Drepo.username=$RepositoryUsername `" `" -Drepo.password=`"`" [redacted]`"`"`" `" --settings=$PSScriptRoot \..\maven.publish.settings.xml`" "
276- mvn $releaseGoal " -DstagingRepositoryId=$stagedRepositoryId " " -DnexusUrl=https://oss.sonatype.org" " -DrepositoryId=target-repo" " -DserverId=target-repo" " -Drepo.username=$RepositoryUsername " " -Drepo.password="" $RepositoryPassword "" " " --settings=$PSScriptRoot \..\maven.publish.settings.xml"
277-
278- if ($LASTEXITCODE -eq 0 ) {
279- Write-Information " Package $ ( $packageDetail.FullyQualifiedName ) deployed"
280- $success = $true
281- break
282- }
283-
284- Write-Information " Release attempt $attempt exited with code $LASTEXITCODE "
285- Write-Information " Checking Maven Central to see if release was successful"
286-
287- if (Test-ReleasedPackage - RepositoryUrl $packageReposityUrl - PackageDetail $packageDetail ) {
288- Write-Information " Package $ ( $packageDetail.FullyQualifiedName ) deployed despite non-zero exit code."
289- $success = $true
290- break
291- }
292- }
293-
294- if (! $success ) {
295- Write-Information ' ##vso[task.logissue type=error]Release to Maven Central failed. For troubleshooting, see https://aka.ms/azsdk/maven-central-tsg'
296- exit 1
297- }
188+ Write-Information " Release attempt $attemt exited with code $LASTEXITCODE "
189+ Write-Information " Checking Azure DevOps to see if release was successful"
190+ if (Test-ReleasedPackage - RepositoryUrl $packageReposityUrl - PackageDetail $packageDetail - BearerToken $RepositoryPassword ) {
191+ Write-Information " Package $ ( $packageDetail.FullyQualifiedName ) deployed despite non-zero exit code."
192+ continue
298193 }
194+
195+ exit $LASTEXITCODE
299196}
300197
301198exit 0
0 commit comments