@@ -31,7 +31,7 @@ export async function run(artifactToolPath: string): Promise<void> {
3131 let version : string ;
3232 let accessToken : string ;
3333 let feedUri : string ;
34- let publishStatus : number ;
34+ let execResult : IExecSyncResult ;
3535 const publishedPackageVar : string = tl . getInput ( "publishedPackageVar" ) ;
3636 const versionRadio = tl . getInput ( "versionPublishSelector" ) ;
3737
@@ -111,13 +111,13 @@ export async function run(artifactToolPath: string): Promise<void> {
111111 packageVersion : version ,
112112 } as artifactToolRunner . IArtifactToolOptions ;
113113
114- publishStatus = publishPackageUsingArtifactTool ( publishDir , publishOptions , toolRunnerOptions ) ;
114+ execResult = publishPackageUsingArtifactTool ( publishDir , publishOptions , toolRunnerOptions ) ;
115115
116116 var retries = 0 ;
117117 let newVersion : string ;
118118
119119 //If package already exist, retry with a newer version, do not retry for custom version
120- while ( retries < numRetries && publishStatus != null && publishStatus === packageAlreadyExistsError && versionRadio !== "custom" ) {
120+ while ( retries < numRetries && execResult != null && execResult . code === packageAlreadyExistsError && versionRadio !== "custom" ) {
121121 [ serviceUri , packageName , feedId , projectId , accessToken ] = authSetup ( feedType ) ;
122122 if ( feedType == "internal" ) {
123123 internalAuthInfo = new auth . InternalAuthInfo ( [ ] , accessToken ) ;
@@ -144,12 +144,19 @@ export async function run(artifactToolPath: string): Promise<void> {
144144 packageVersion : newVersion ,
145145 } as artifactToolRunner . IArtifactToolOptions ;
146146 tl . debug ( tl . loc ( "Info_PublishingRetry" , publishOptions . packageName , version , newVersion ) ) ;
147- publishStatus = publishPackageUsingArtifactTool ( publishDir , publishOptions , toolRunnerOptions ) ;
147+ execResult = publishPackageUsingArtifactTool ( publishDir , publishOptions , toolRunnerOptions ) ;
148148 version = newVersion ;
149149 retries ++ ;
150150 }
151151
152- if ( publishedPackageVar ) {
152+ if ( execResult . code === packageAlreadyExistsError ) {
153+ telemetry . logResult ( "Packaging" , "UniversalPackagesCommand" , execResult . code ) ;
154+ throw new Error ( tl . loc ( "Error_UnexpectedErrorArtifactTool" ,
155+ execResult . code ,
156+ execResult . stderr ? execResult . stderr . trim ( ) : execResult . stderr ) ) ;
157+ }
158+
159+ if ( publishedPackageVar ) {
153160 tl . setVariable ( publishedPackageVar , `${ packageName } ${ version } ` ) ;
154161 }
155162
@@ -197,7 +204,7 @@ function publishPackageUsingArtifactTool(
197204
198205 //Retry if package exist error occurs
199206 if ( execResult . code == packageAlreadyExistsError ) {
200- return execResult . code ;
207+ return execResult ;
201208 }
202209
203210 telemetry . logResult ( "Packaging" , "UniversalPackagesCommand" , execResult . code ) ;
@@ -219,10 +226,10 @@ async function getNextPackageVersion(
219226 projectId ,
220227 feedId ,
221228 packageName ) ;
222-
229+
223230 if ( highestVersion != null ) {
224- version = artifactToolUtilities . getVersionUtility ( tl . getInput ( "versionPublishSelector" ) , highestVersion ) ;
225- }
231+ version = artifactToolUtilities . getVersionUtility ( tl . getInput ( "versionPublishSelector" ) , highestVersion ) ;
232+ }
226233
227234 if ( version == null ) {
228235 throw new Error ( tl . loc ( "FailedToGetLatestPackageVersion" ) ) ;
0 commit comments