@@ -4,7 +4,7 @@ import * as path from "path";
44import * as ngToolRunner from "azure-pipelines-tasks-packaging-common/nuget/NuGetToolRunner2" ;
55import * as packUtils from "azure-pipelines-tasks-packaging-common/PackUtilities" ;
66import INuGetCommandOptions from "azure-pipelines-tasks-packaging-common/nuget/INuGetCommandOptions2" ;
7- import { IExecSyncResult } from "azure-pipelines-task-lib/toolrunner" ;
7+ import { IExecOptions } from "azure-pipelines-task-lib/toolrunner" ;
88import * as telemetry from "azure-pipelines-tasks-utility-common/telemetry" ;
99
1010class PackOptions implements INuGetCommandOptions {
@@ -42,26 +42,22 @@ export async function run(nuGetPath: string): Promise<void> {
4242 let toolPackage = tl . getBoolInput ( "toolPackage" ) ;
4343 let outputDir = undefined ;
4444
45- try
46- {
45+ try {
4746 // If outputDir is not provided then the root working directory is set by default.
4847 // By requiring it, it will throw an error if it is not provided and we can set it to undefined.
4948 outputDir = tl . getPathInput ( "outputDir" , true ) ;
5049 }
51- catch ( error )
52- {
50+ catch ( error ) {
5351 outputDir = undefined ;
5452 }
5553
56- try {
57- if ( versioningScheme !== "off" && includeRefProj )
58- {
54+ try {
55+ if ( versioningScheme !== "off" && includeRefProj ) {
5956 tl . warning ( tl . loc ( "Warning_AutomaticallyVersionReferencedProjects" ) ) ;
6057 }
6158
6259 let version : string = undefined ;
63- switch ( versioningScheme )
64- {
60+ switch ( versioningScheme ) {
6561 case "off" :
6662 break ;
6763 case "byPrereleaseNumber" :
@@ -73,34 +69,30 @@ export async function run(nuGetPath: string): Promise<void> {
7369 case "byEnvVar" :
7470 tl . debug ( `Getting version from env var: ${ versionEnvVar } ` ) ;
7571 version = tl . getVariable ( versionEnvVar ) ;
76- if ( ! version )
77- {
72+ if ( ! version ) {
7873 tl . setResult ( tl . TaskResult . Failed , tl . loc ( "Error_NoValueFoundForEnvVar" ) ) ;
7974 break ;
8075 }
8176 break ;
8277 case "byBuildNumber" :
8378 tl . debug ( "Getting version number from build number" )
8479
85- if ( tl . getVariable ( "SYSTEM_HOSTTYPE" ) === "release" )
86- {
80+ if ( tl . getVariable ( "SYSTEM_HOSTTYPE" ) === "release" ) {
8781 tl . setResult ( tl . TaskResult . Failed , tl . loc ( "Error_AutomaticallyVersionReleases" ) ) ;
8882 return ;
8983 }
9084
91- let buildNumber : string = tl . getVariable ( "BUILD_BUILDNUMBER" ) ;
85+ let buildNumber : string = tl . getVariable ( "BUILD_BUILDNUMBER" ) ;
9286 tl . debug ( `Build number: ${ buildNumber } ` ) ;
9387
9488 let versionRegex = / \d + \. \d + \. \d + (?: \. \d + ) ? / ;
9589 let versionMatches = buildNumber . match ( versionRegex ) ;
96- if ( ! versionMatches )
97- {
90+ if ( ! versionMatches ) {
9891 tl . setResult ( tl . TaskResult . Failed , tl . loc ( "Error_NoVersionFoundInBuildNumber" ) ) ;
9992 return ;
10093 }
10194
102- if ( versionMatches . length > 1 )
103- {
95+ if ( versionMatches . length > 1 ) {
10496 tl . warning ( tl . loc ( "Warning_MoreThanOneVersionInBuildNumber" ) )
10597 }
10698
@@ -110,8 +102,7 @@ export async function run(nuGetPath: string): Promise<void> {
110102
111103 tl . debug ( `Version to use: ${ version } ` ) ;
112104
113- if ( outputDir && ! tl . exist ( outputDir ) )
114- {
105+ if ( outputDir && ! tl . exist ( outputDir ) ) {
115106 tl . debug ( `Creating output directory: ${ outputDir } ` ) ;
116107 tl . mkdirP ( outputDir ) ;
117108 }
@@ -134,12 +125,10 @@ export async function run(nuGetPath: string): Promise<void> {
134125 } ) ;
135126
136127 let props : string [ ] = [ ] ;
137- if ( configuration && configuration !== "$(BuildConfiguration)" )
138- {
128+ if ( configuration && configuration !== "$(BuildConfiguration)" ) {
139129 props . push ( `Configuration=${ configuration } ` ) ;
140130 }
141- if ( propertiesInput )
142- {
131+ if ( propertiesInput ) {
143132 props = props . concat ( propertiesInput . split ( ";" ) ) ;
144133 }
145134
@@ -161,15 +150,15 @@ export async function run(nuGetPath: string): Promise<void> {
161150 environmentSettings ) ;
162151
163152 for ( const file of filesList ) {
164- pack ( file , packOptions ) ;
153+ await pack ( file , packOptions ) ;
165154 }
166155 } catch ( err ) {
167156 tl . error ( err ) ;
168157 tl . setResult ( tl . TaskResult . Failed , tl . loc ( "Error_PackageFailure" ) ) ;
169158 }
170159}
171160
172- function pack ( file : string , options : PackOptions ) : IExecSyncResult {
161+ async function pack ( file : string , options : PackOptions ) : Promise < number > {
173162 console . log ( tl . loc ( "Info_AttemptingToPackFile" ) + file ) ;
174163
175164 let nugetTool = ngToolRunner . createNuGetToolRunner ( options . nuGetPath , options . environment , undefined ) ;
@@ -210,12 +199,20 @@ function pack(file: string, options: PackOptions): IExecSyncResult {
210199 nugetTool . arg ( options . verbosity ) ;
211200 }
212201
213- let execResult = nugetTool . execSync ( ) ;
214- if ( execResult . code !== 0 ) {
215- telemetry . logResult ( 'Packaging' , 'NuGetCommand' , execResult . code ) ;
202+ // Listen for stderr output to write timeline results for the build.
203+ let stdErrText = "" ;
204+ nugetTool . on ( 'stderr' , ( data : Buffer ) => {
205+ stdErrText += data . toString ( 'utf-8' ) ;
206+ } ) ;
207+
208+ const execResult = await nugetTool . exec ( { ignoreReturnCode : true } as IExecOptions ) ;
209+
210+ if ( execResult !== 0 ) {
211+ telemetry . logResult ( 'Packaging' , 'NuGetCommand' , execResult ) ;
216212 throw tl . loc ( "Error_NugetFailedWithCodeAndErr" ,
217- execResult . code ,
218- execResult . stderr ? execResult . stderr . trim ( ) : execResult . stderr ) ;
213+ execResult ,
214+ stdErrText . trim ( ) ) ;
219215 }
216+
220217 return execResult ;
221218}
0 commit comments