@@ -4,7 +4,7 @@ import * as path from "path";
4
4
import * as ngToolRunner from "azure-pipelines-tasks-packaging-common/nuget/NuGetToolRunner2" ;
5
5
import * as packUtils from "azure-pipelines-tasks-packaging-common/PackUtilities" ;
6
6
import 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" ;
8
8
import * as telemetry from "azure-pipelines-tasks-utility-common/telemetry" ;
9
9
10
10
class PackOptions implements INuGetCommandOptions {
@@ -42,26 +42,22 @@ export async function run(nuGetPath: string): Promise<void> {
42
42
let toolPackage = tl . getBoolInput ( "toolPackage" ) ;
43
43
let outputDir = undefined ;
44
44
45
- try
46
- {
45
+ try {
47
46
// If outputDir is not provided then the root working directory is set by default.
48
47
// By requiring it, it will throw an error if it is not provided and we can set it to undefined.
49
48
outputDir = tl . getPathInput ( "outputDir" , true ) ;
50
49
}
51
- catch ( error )
52
- {
50
+ catch ( error ) {
53
51
outputDir = undefined ;
54
52
}
55
53
56
- try {
57
- if ( versioningScheme !== "off" && includeRefProj )
58
- {
54
+ try {
55
+ if ( versioningScheme !== "off" && includeRefProj ) {
59
56
tl . warning ( tl . loc ( "Warning_AutomaticallyVersionReferencedProjects" ) ) ;
60
57
}
61
58
62
59
let version : string = undefined ;
63
- switch ( versioningScheme )
64
- {
60
+ switch ( versioningScheme ) {
65
61
case "off" :
66
62
break ;
67
63
case "byPrereleaseNumber" :
@@ -73,34 +69,30 @@ export async function run(nuGetPath: string): Promise<void> {
73
69
case "byEnvVar" :
74
70
tl . debug ( `Getting version from env var: ${ versionEnvVar } ` ) ;
75
71
version = tl . getVariable ( versionEnvVar ) ;
76
- if ( ! version )
77
- {
72
+ if ( ! version ) {
78
73
tl . setResult ( tl . TaskResult . Failed , tl . loc ( "Error_NoValueFoundForEnvVar" ) ) ;
79
74
break ;
80
75
}
81
76
break ;
82
77
case "byBuildNumber" :
83
78
tl . debug ( "Getting version number from build number" )
84
79
85
- if ( tl . getVariable ( "SYSTEM_HOSTTYPE" ) === "release" )
86
- {
80
+ if ( tl . getVariable ( "SYSTEM_HOSTTYPE" ) === "release" ) {
87
81
tl . setResult ( tl . TaskResult . Failed , tl . loc ( "Error_AutomaticallyVersionReleases" ) ) ;
88
82
return ;
89
83
}
90
84
91
- let buildNumber : string = tl . getVariable ( "BUILD_BUILDNUMBER" ) ;
85
+ let buildNumber : string = tl . getVariable ( "BUILD_BUILDNUMBER" ) ;
92
86
tl . debug ( `Build number: ${ buildNumber } ` ) ;
93
87
94
88
let versionRegex = / \d + \. \d + \. \d + (?: \. \d + ) ? / ;
95
89
let versionMatches = buildNumber . match ( versionRegex ) ;
96
- if ( ! versionMatches )
97
- {
90
+ if ( ! versionMatches ) {
98
91
tl . setResult ( tl . TaskResult . Failed , tl . loc ( "Error_NoVersionFoundInBuildNumber" ) ) ;
99
92
return ;
100
93
}
101
94
102
- if ( versionMatches . length > 1 )
103
- {
95
+ if ( versionMatches . length > 1 ) {
104
96
tl . warning ( tl . loc ( "Warning_MoreThanOneVersionInBuildNumber" ) )
105
97
}
106
98
@@ -110,8 +102,7 @@ export async function run(nuGetPath: string): Promise<void> {
110
102
111
103
tl . debug ( `Version to use: ${ version } ` ) ;
112
104
113
- if ( outputDir && ! tl . exist ( outputDir ) )
114
- {
105
+ if ( outputDir && ! tl . exist ( outputDir ) ) {
115
106
tl . debug ( `Creating output directory: ${ outputDir } ` ) ;
116
107
tl . mkdirP ( outputDir ) ;
117
108
}
@@ -134,12 +125,10 @@ export async function run(nuGetPath: string): Promise<void> {
134
125
} ) ;
135
126
136
127
let props : string [ ] = [ ] ;
137
- if ( configuration && configuration !== "$(BuildConfiguration)" )
138
- {
128
+ if ( configuration && configuration !== "$(BuildConfiguration)" ) {
139
129
props . push ( `Configuration=${ configuration } ` ) ;
140
130
}
141
- if ( propertiesInput )
142
- {
131
+ if ( propertiesInput ) {
143
132
props = props . concat ( propertiesInput . split ( ";" ) ) ;
144
133
}
145
134
@@ -161,15 +150,15 @@ export async function run(nuGetPath: string): Promise<void> {
161
150
environmentSettings ) ;
162
151
163
152
for ( const file of filesList ) {
164
- pack ( file , packOptions ) ;
153
+ await pack ( file , packOptions ) ;
165
154
}
166
155
} catch ( err ) {
167
156
tl . error ( err ) ;
168
157
tl . setResult ( tl . TaskResult . Failed , tl . loc ( "Error_PackageFailure" ) ) ;
169
158
}
170
159
}
171
160
172
- function pack ( file : string , options : PackOptions ) : IExecSyncResult {
161
+ async function pack ( file : string , options : PackOptions ) : Promise < number > {
173
162
console . log ( tl . loc ( "Info_AttemptingToPackFile" ) + file ) ;
174
163
175
164
let nugetTool = ngToolRunner . createNuGetToolRunner ( options . nuGetPath , options . environment , undefined ) ;
@@ -210,12 +199,20 @@ function pack(file: string, options: PackOptions): IExecSyncResult {
210
199
nugetTool . arg ( options . verbosity ) ;
211
200
}
212
201
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 ) ;
216
212
throw tl . loc ( "Error_NugetFailedWithCodeAndErr" ,
217
- execResult . code ,
218
- execResult . stderr ? execResult . stderr . trim ( ) : execResult . stderr ) ;
213
+ execResult ,
214
+ stdErrText . trim ( ) ) ;
219
215
}
216
+
220
217
return execResult ;
221
218
}
0 commit comments