public static DotNetCliCommandResult Execute(DotNetCliCommand parameters)
        {
            using (var process = new Process {
                StartInfo = BuildStartInfo(parameters.CliPath, parameters.GenerateResult.ArtifactsPaths.BuildArtifactsDirectoryPath, parameters.Arguments, parameters.EnvironmentVariables)
            })
                using (var outputReader = new AsyncProcessOutputReader(process, parameters.LogOutput, parameters.Logger))
                    using (new ConsoleExitHandler(process, parameters.Logger))
                    {
                        parameters.Logger.WriteLineInfo($"// start {parameters.CliPath ?? "dotnet"} {parameters.Arguments} in {parameters.GenerateResult.ArtifactsPaths.BuildArtifactsDirectoryPath}");

                        var stopwatch = Stopwatch.StartNew();

                        process.Start();
                        outputReader.BeginRead();

                        if (!process.WaitForExit((int)parameters.Timeout.TotalMilliseconds))
                        {
                            parameters.Logger.WriteLineError($"// command took longer than the timeout: {parameters.Timeout.TotalSeconds:0.##}s. Killing the process tree!");

                            outputReader.CancelRead();
                            process.KillTree();

                            return(DotNetCliCommandResult.Failure(stopwatch.Elapsed, $"The configured timeout {parameters.Timeout} was reached!" + outputReader.GetErrorText(), outputReader.GetOutputText()));
                        }

                        stopwatch.Stop();
                        outputReader.StopRead();

                        parameters.Logger.WriteLineInfo($"// command took {stopwatch.Elapsed.TotalSeconds:0.##}s and exited with {process.ExitCode}");

                        return(process.ExitCode <= 0
                    ? DotNetCliCommandResult.Success(stopwatch.Elapsed, outputReader.GetOutputText())
                    : DotNetCliCommandResult.Failure(stopwatch.Elapsed, outputReader.GetOutputText(), outputReader.GetErrorText()));
                    }
        }
Пример #2
0
        protected override void GenerateBuildScript(BuildPartition buildPartition, ArtifactsPaths artifactsPaths)
        {
            var content = new StringBuilder(300)
                          .AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition)}")
                          .AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(buildPartition)}")
                          .ToString();

            File.WriteAllText(artifactsPaths.BuildScriptFilePath, content);
        }
        internal static void LogEnvVars(DotNetCliCommand command)
        {
            if (!command.LogOutput)
            {
                return;
            }

            ProcessStartInfo startInfo = BuildStartInfo(
                command.CliPath, command.GenerateResult.ArtifactsPaths.BuildArtifactsDirectoryPath, command.Arguments, command.EnvironmentVariables);

            if (startInfo.EnvironmentVariables.Keys.Count > 0)
            {
                command.Logger.WriteLineInfo("// Environment Variables:");
                foreach (string name in startInfo.EnvironmentVariables.Keys)
                {
                    command.Logger.WriteLine($"\t[{name}] = \"{startInfo.EnvironmentVariables[name]}\"");
                }
            }
        }
Пример #4
0
        public static DotNetCliCommandResult Execute(DotNetCliCommand parameters)
        {
            using (var process = new Process {
                StartInfo = BuildStartInfo(parameters.CliPath, parameters.GenerateResult.ArtifactsPaths.BuildArtifactsDirectoryPath, parameters.Arguments, parameters.EnvironmentVariables)
            })
            {
                parameters.Logger.WriteLineInfo($"// start {parameters.CliPath ?? "dotnet"} {parameters.Arguments} in {parameters.GenerateResult.ArtifactsPaths.BuildArtifactsDirectoryPath}");

                var standardOutput = new StringBuilder(1000);
                var standardError  = new StringBuilder();

                process.OutputDataReceived += (sender, args) => standardOutput.AppendLine(args.Data);
                process.ErrorDataReceived  += (sender, args) => standardError.AppendLine(args.Data);

                var stopwatch = Stopwatch.StartNew();

                process.Start();

                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                if (!process.WaitForExit((int)parameters.Timeout.TotalMilliseconds))
                {
                    parameters.Logger.WriteLineError($"// command took more that the timeout: {parameters.Timeout.TotalSeconds:0.##}s. Killing the process tree!");

                    process.KillTree();

                    return(DotNetCliCommandResult.Failure(stopwatch.Elapsed, $"The configured timeout {parameters.Timeout} was reached!" + standardError.ToString(), standardOutput.ToString()));
                }

                stopwatch.Stop();

                parameters.Logger.WriteLineInfo($"// command took {stopwatch.Elapsed.TotalSeconds:0.##}s and exited with {process.ExitCode}");

                return(process.ExitCode <= 0
                    ? DotNetCliCommandResult.Success(stopwatch.Elapsed, standardOutput.ToString())
                    : DotNetCliCommandResult.Failure(stopwatch.Elapsed, standardError.ToString(), standardOutput.ToString()));
            }
        }
Пример #5
0
        public static DotNetCliCommandResult Execute(DotNetCliCommand parameters)
        {
            using (var process = new Process {
                StartInfo = BuildStartInfo(parameters.CliPath, parameters.GenerateResult.ArtifactsPaths.BuildArtifactsDirectoryPath, parameters.Arguments, parameters.EnvironmentVariables)
            })
            {
                parameters.Logger.WriteLineInfo($"// start {parameters.CliPath ?? "dotnet"} {parameters.Arguments} in {parameters.GenerateResult.ArtifactsPaths.BuildArtifactsDirectoryPath}");

                var stopwatch = Stopwatch.StartNew();
                process.Start();

                string standardOutput = process.StandardOutput.ReadToEnd();
                string standardError  = process.StandardError.ReadToEnd();

                process.WaitForExit();
                stopwatch.Stop();

                parameters.Logger.WriteLineInfo($"// command took {stopwatch.Elapsed.TotalSeconds:0.##}s and exited with {process.ExitCode}");

                return(process.ExitCode <= 0
                    ? DotNetCliCommandResult.Success(stopwatch.Elapsed, standardOutput)
                    : DotNetCliCommandResult.Failure(stopwatch.Elapsed, standardError, standardOutput));
            }
        }