@@ -38,6 +38,8 @@ import (
38
38
39
39
"github.com/libgit2/git2go"
40
40
"github.com/getsentry/raven-go"
41
+ "strconv"
42
+ "path/filepath"
41
43
)
42
44
43
45
type scriptVariables struct {
@@ -286,7 +288,7 @@ func processBranch(config *Configuration, proj ProjectConfig, twd string, branch
286
288
287
289
Log .Debugf (" [%s] - processing artifacts from pick-up location...\n " , proj .Path )
288
290
runPreProcessArtifacts (& artifacts , & proj .Path , & branchName )
289
- processArtifacts (config .Home , artifacts , proj .Path , branchName )
291
+ processArtifacts (config .Home , twd , artifacts , proj .Path , branchName )
290
292
runPostProcessArtifacts (& artifacts , & proj .Path , & branchName )
291
293
292
294
runPostProcessBranch (& twd , & branchName , & description )
@@ -299,7 +301,7 @@ func runProjectScripts(dir string, branchName string, proj ProjectConfig) {
299
301
for _ , script := range proj .Scripts {
300
302
301
303
// Setup the variables that can be substituted in the script for this run
302
- Log .Debugf (" [%s] - preparing project script: \" %s\" ...\n " , proj .Path , script )
304
+ Log .Debugf (" [%s] - preparing project script %d : \" %s\" ...\n " , proj .Path , scriptIndex , script )
303
305
304
306
scriptSubs := scriptVariables {proj .Path , branchName , proj .URL , proj .Artifacts }
305
307
@@ -311,10 +313,10 @@ func runProjectScripts(dir string, branchName string, proj ProjectConfig) {
311
313
}
312
314
scriptFinalStr := scriptFinal .String ()
313
315
314
- Log .Debugf (" [%s] - executing project script: \" %s\" ...\n " , proj .Path , scriptFinalStr )
316
+ Log .Debugf (" [%s] - executing project script %d : \" %s\" ...\n " , proj .Path , scriptIndex , scriptFinalStr )
315
317
316
318
stdout , stderr , err := execInDir (dir , scriptFinalStr )
317
- writeProjectLogs (stdout , stderr , scriptIndex , dir + "/" + proj . Artifacts )
319
+ writeProjectLogs (stdout , stderr , scriptIndex , dir )
318
320
if err != nil {
319
321
Log .Debugf (" [%s] - error executing project script %d: \" %s\" ...\n " , proj .Path , scriptIndex , scriptFinalStr )
320
322
Log .Debugf ("%s\n " , string (stdout ))
@@ -351,7 +353,7 @@ func execInDir(dir string, command string) (string, string, error) {
351
353
352
354
func writeProjectLogs ( stdout string , stderr string , index int , dir string ) {
353
355
// Open the output log for writing
354
- soLogFile , soErr := os .Create ( dir + "/go-build-stdout_" + string (index ) + ".log" )
356
+ soLogFile , soErr := os .Create ( dir + "/go-build-stdout_" + strconv . Itoa (index ) + ".log" )
355
357
if soErr != nil {
356
358
// Fatal error
357
359
raven .CaptureErrorAndWait (soErr , nil )
@@ -369,7 +371,7 @@ func writeProjectLogs( stdout string, stderr string, index int, dir string ) {
369
371
soLogFile .Close ()
370
372
371
373
// Open the error log for writing
372
- seLogFile , seErr := os .Create ( dir + "/go-build-stderr_" + string (index ) + ".log" )
374
+ seLogFile , seErr := os .Create ( dir + "/go-build-stderr_" + strconv . Itoa (index ) + ".log" )
373
375
if seErr != nil {
374
376
// Fatal error
375
377
raven .CaptureErrorAndWait (seErr , nil )
@@ -387,7 +389,7 @@ func writeProjectLogs( stdout string, stderr string, index int, dir string ) {
387
389
seLogFile .Close ()
388
390
}
389
391
390
- func processArtifacts (home string , artifacts string , project string , branchName string ) {
392
+ func processArtifacts (home string , projectDir string , artifacts string , project string , branchName string ) {
391
393
Log .Infof (" [%s] - processing build artifacts for project \" %s\" , branch \" %s\" .\n " , project , project , branchName )
392
394
393
395
destination := home + "/artifacts/" + project + "/" + branchName
@@ -420,5 +422,27 @@ func processArtifacts(home string, artifacts string, project string, branchName
420
422
panic (mvErr )
421
423
}
422
424
425
+ logGlob := projectDir + "/*.log"
426
+ Log .Debugf (" [%s] - searching for build logs using glob: \" %s\" \n " , project , logGlob )
427
+ logFiles , lfErr := filepath .Glob (logGlob )
428
+ if lfErr != nil {
429
+ raven .CaptureErrorAndWait (lfErr , nil )
430
+ Log .Critical (lfErr )
431
+ panic (lfErr )
432
+ }
433
+
434
+ Log .Debugf (" [%s] - project has %d log files\n " , project , len (logFiles ))
435
+
436
+ for _ , f := range logFiles {
437
+ lFile := filepath .Base (f )
438
+ Log .Debugf (" [%s] - moving log file \" %s\" to destination\n " , project , lFile )
439
+ mvLfErr := os .Rename (f , destination + "/" + lFile )
440
+ if mvLfErr != nil {
441
+ raven .CaptureErrorAndWait (mvLfErr , nil )
442
+ Log .Critical (mvLfErr )
443
+ panic (mvLfErr )
444
+ }
445
+ }
446
+
423
447
Log .Debugf (" [%s] - artifact processing completed.\n " , project )
424
448
}
0 commit comments