@@ -12,6 +12,9 @@ const logger = require('./logger').winstonLogger,
1212 config = require ( "./config" ) ;
1313
1414
15+ let BUILD_ARTIFACTS_TOTAL_COUNT = 0 ;
16+ let BUILD_ARTIFACTS_FAIL_COUNT = 0 ;
17+
1518const parseAndDownloadArtifacts = async ( buildId , data ) => {
1619 return new Promise ( async ( resolve , reject ) => {
1720 let all_promises = [ ] ;
@@ -23,9 +26,9 @@ const parseAndDownloadArtifacts = async (buildId, data) => {
2326 let sessionId = sessions [ j ] ;
2427 let filePath = path . join ( './' , 'build_artifacts' , buildId , comb , sessionId ) ;
2528 let fileName = 'build_artifacts.zip' ;
26- process . env . BUILD_ARTIFACTS_TOTAL_COUNT = Number ( process . env . BUILD_ARTIFACTS_TOTAL_COUNT ) + 1
29+ BUILD_ARTIFACTS_TOTAL_COUNT += 1 ;
2730 all_promises . push ( downloadAndUnzip ( filePath , fileName , data [ comb ] [ sessionId ] ) . catch ( ( error ) => {
28- process . env . BUILD_ARTIFACTS_FAIL_COUNT = Number ( process . env . BUILD_ARTIFACTS_FAIL_COUNT ) + 1 ;
31+ BUILD_ARTIFACTS_FAIL_COUNT = BUILD_ARTIFACTS_FAIL_COUNT + 1 ;
2932 reject ( error ) ;
3033 } ) ) ;
3134 }
@@ -142,8 +145,8 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options) => {
142145 let data = {
143146 feature_usage : {
144147 downloads : {
145- eligible_download_folders : Number ( process . env . BUILD_ARTIFACTS_TOTAL_COUNT ) ,
146- successfully_downloaded_folders : Number ( process . env . BUILD_ARTIFACTS_TOTAL_COUNT ) - Number ( process . env . BUILD_ARTIFACTS_FAIL_COUNT )
148+ eligible_download_folders : BUILD_ARTIFACTS_TOTAL_COUNT ,
149+ successfully_downloaded_folders : BUILD_ARTIFACTS_TOTAL_COUNT - BUILD_ARTIFACTS_FAIL_COUNT
147150 } ,
148151 reporter : reporter
149152 }
@@ -157,8 +160,8 @@ const sendUpdatesToBstack = async (bsConfig, buildId, args, options) => {
157160}
158161
159162exports . downloadBuildArtifacts = async ( bsConfig , buildId , args ) => {
160- process . env . BUILD_ARTIFACTS_FAIL_COUNT = 0 ;
161- process . env . BUILD_ARTIFACTS_TOTAL_COUNT = 0 ;
163+ BUILD_ARTIFACTS_FAIL_COUNT = 0 ;
164+ BUILD_ARTIFACTS_TOTAL_COUNT = 0 ;
162165
163166 let url = `${ config . buildUrl } ${ buildId } /build_artifacts` ;
164167 let options = {
@@ -182,9 +185,9 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
182185 await createDirectories ( buildId , buildDetails ) ;
183186 await parseAndDownloadArtifacts ( buildId , buildDetails ) ;
184187
185- if ( process . env . BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
188+ if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
186189 messageType = Constants . messageTypes . ERROR ;
187- message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , process . env . BUILD_ARTIFACTS_FAIL_COUNT ) ;
190+ message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , BUILD_ARTIFACTS_FAIL_COUNT ) ;
188191 logger . error ( message ) ;
189192 } else {
190193 messageType = Constants . messageTypes . SUCCESS ;
@@ -198,13 +201,12 @@ exports.downloadBuildArtifacts = async (bsConfig, buildId, args) => {
198201 messageType = Constants . messageTypes . ERROR ;
199202 errorCode = 'api_failed_build_artifacts' ;
200203
201- if ( process . env . BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
204+ if ( BUILD_ARTIFACTS_FAIL_COUNT > 0 ) {
202205 messageType = Constants . messageTypes . ERROR ;
203- message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , process . env . BUILD_ARTIFACTS_FAIL_COUNT ) ;
206+ message = Constants . userMessages . DOWNLOAD_BUILD_ARTIFACTS_FAILED . replace ( '<build-id>' , buildId ) . replace ( '<machine-count>' , BUILD_ARTIFACTS_FAIL_COUNT ) ;
204207 logger . error ( message ) ;
205208 } else {
206209 logger . error ( 'Downloading the build artifacts failed.' ) ;
207- logger . error ( err ) ;
208210 }
209211
210212 utils . sendUsageReport ( bsConfig , args , err , messageType , errorCode ) ;
0 commit comments