Esempio n. 1
0
        private static void Execute(
            NukeBuild build,
            ExecutableTarget target,
            IReadOnlyCollection <string> previouslyExecutedTargets,
            bool failureMode = false)
        {
            if (target.Status == ExecutionStatus.Skipped ||
                previouslyExecutedTargets.Contains(target.Name) ||
                HasSkippingCondition(target, target.DynamicConditions))
            {
                target.Status = ExecutionStatus.Skipped;
                build.ExecuteExtension <IOnTargetSkipped>(x => x.OnTargetSkipped(build, target));
                AppendToBuildAttemptFile(target.Name);
                return;
            }

            if (target.Actions.Count == 0)
            {
                target.Status = ExecutionStatus.Collective;
                return;
            }

            using (Logging.SetTarget(target.Name))
                using (build.WriteTarget(target.Name))
                {
                    target.Stopwatch.Start();
                    target.Status = ExecutionStatus.Running;
                    build.ExecuteExtension <IOnTargetRunning>(x => x.OnTargetRunning(build, target));
                    try
                    {
                        target.Actions.ForEach(x => x());
                        target.Stopwatch.Stop();
                        target.Status = ExecutionStatus.Succeeded;
                        build.ExecuteExtension <IOnTargetSucceeded>(x => x.OnTargetSucceeded(build, target));

                        AppendToBuildAttemptFile(target.Name);
                    }
                    catch (Exception exception)
                    {
                        exception = exception.Unwrap();
                        if (!target.SummaryInformation.Any())
                        {
                            build.ReportSummary(
                                target,
                                _ => _.AddPair(exception.GetType().Name, exception.Message.SplitLineBreaks().First()));
                        }

                        Log.Error(exception, "Target {TargetName} has thrown an exception", target.Name);

                        target.Stopwatch.Stop();
                        target.Status = ExecutionStatus.Failed;
                        build.ExecuteExtension <IOnTargetFailed>(x => x.OnTargetFailed(build, target));

                        if (!target.ProceedAfterFailure && !failureMode)
                        {
                            throw new TargetExecutionException(target.Name, exception);
                        }
                    }
                }
        }
Esempio n. 2
0
        private static void Execute(
            NukeBuild build,
            ExecutableTarget target,
            IReadOnlyCollection <string> previouslyExecutedTargets,
            bool failureMode = false)
        {
            if (target.Status == ExecutionStatus.Skipped ||
                previouslyExecutedTargets.Contains(target.Name) ||
                HasSkippingCondition(target, target.DynamicConditions))
            {
                target.Status = ExecutionStatus.Skipped;
                build.ExecuteExtension <IOnTargetSkipped>(x => x.OnTargetSkipped(build, target));
                AppendToBuildAttemptFile(target.Name);
                return;
            }

            if (target.Actions.Count == 0)
            {
                target.Status = ExecutionStatus.Collective;
                return;
            }

            using (Logger.Block(target.Name))
            {
                target.Status = ExecutionStatus.Running;
                build.ExecuteExtension <IOnTargetRunning>(x => x.OnTargetRunning(build, target));
                var stopwatch = Stopwatch.StartNew();
                try
                {
                    target.Actions.ForEach(x => x());
                    target.Status = ExecutionStatus.Succeeded;
                    build.ExecuteExtension <IOnTargetSucceeded>(x => x.OnTargetSucceeded(build, target));
                    AppendToBuildAttemptFile(target.Name);
                }
                catch (Exception exception)
                {
                    build.ReportSummary(_ =>
                                        target.SummaryInformation.Any()
                            ? target.SummaryInformation
                            : _.AddPair(exception.GetType().Name, exception.Message));

                    Logger.Error(exception);
                    target.Status = ExecutionStatus.Failed;

                    build.ExecuteExtension <IOnTargetFailed>(x => x.OnTargetFailed(build, target));
                    if (!target.ProceedAfterFailure && !failureMode)
                    {
                        throw new TargetExecutionException(target.Name, exception);
                    }
                }
                finally
                {
                    target.Duration = stopwatch.Elapsed;
                }
            }
        }