public sealed override void Apply(Environment env, Parameter[] parameters, FailedBuildTokenSource failedBuildTokenSource, LoggerList loggers)
 {
     foreach (Parameter parameter in parameters)
     {
         env.Properties.Add(parameter.Name, parameter.Value);
     }
 }
Beispiel #2
0
        public void Run(CancellationToken taskCancelToken, LoggerList loggers)
        {
            //Create Build Object
            Build build = CreateBuild();
            //Create Job Build logger
            JobBuildLogger buildLogger = new JobBuildLogger(Name, build.Number);

            loggers.AddLogger(buildLogger);

            //Start Execution

            buildLogger.Log(new Log("Start at " + DateTime.Now + "\n"));

            FailedBuildTokenSource failedTokenSource = new FailedBuildTokenSource();

            try
            {
                //Create the build Environment
                Class.Environment env = new Class.Environment();

                foreach (Property prop in Properties)
                {
                    prop.Definition.Apply(env, prop.Parameters.ToArray(), failedTokenSource, loggers);
                    CheckIfBuildCanceled(taskCancelToken, build, buildLogger);
                    failedTokenSource.Token.ThrowIfFailed();
                }

                env.Properties.Add("buildNumber", build.Number.ToString());

                PreBuild(build, env, taskCancelToken, failedTokenSource, loggers);
                Build(build, env, taskCancelToken, failedTokenSource, loggers);
                AfterBuild(build, env, taskCancelToken, failedTokenSource, loggers);

                buildLogger.Log(new Log("\nBUILD SUCCESS"));
                buildLogger.Log(new Log("\nEnd at " + DateTime.Now));

                build.Status = "SUCCESS";
            }
            catch (OperationCanceledException e)
            {
                throw e;
            }
            catch (FailedBuildException e)
            {
                build.Status = "FAILED";
                buildLogger.Log(new Log("BUILD FAILED"));
                buildLogger.Log(new Log("\nEnd at " + DateTime.Now));
            }
        }
Beispiel #3
0
        public sealed override void Apply(Environment env, Parameter[] parameters, FailedBuildTokenSource failedBuildTokenSource, LoggerList loggers)
        {
            string command = parameters.Single(o => o.Name == "command").Value;

            ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);

            string directory = Path.Combine(System.Environment.CurrentDirectory, "jobs", env.Properties["jobName"]);

            JobBuildLogger.JobBuildLogger buildLogger = loggers.GetLogger <JobBuildLogger.JobBuildLogger>();

            buildLogger.Log(new Log("[windows-batch] : " + command));

            Process process = new Process();

            process.StartInfo.WorkingDirectory       = directory;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.OutputDataReceived += (sender, args) => buildLogger.Log(new Log(args.Data));
            process.ErrorDataReceived  += (sender, args) => buildLogger.Log(new Log(args.Data));

            foreach (KeyValuePair <string, string> prop in env.Properties)
            {
                process.StartInfo.Environment.Add(prop.Key.ToUpper(), prop.Value);
            }

            Node node = new Node()
            {
                WorkSpace = "C:",
                IpAddress = "machine"
            };

            node.Execute(process, command);

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

            process.WaitForExit();

            if (process.ExitCode != 0)
            {
                failedBuildTokenSource.Failed();
            }
        }
Beispiel #4
0
 public virtual void AfterBuild(Build build, Class.Environment env, CancellationToken taskCancelToken, FailedBuildTokenSource failedBuildTokenSource, LoggerList loggers)
 {
 }
Beispiel #5
0
 public abstract void Build(Build build, Class.Environment env, CancellationToken taskCancelToken, FailedBuildTokenSource failedBuildTokenSource, LoggerList loggers);
Beispiel #6
0
 public abstract void Apply(Environment env, Parameter[] parameters, FailedBuildTokenSource failedBuildTokenSource, LoggerList loggers);
Beispiel #7
0
 public sealed override void AfterBuild(Build build, Environment env, CancellationToken taskCancelToken, FailedBuildTokenSource failedBuildTokenSource, LoggerList loggers)
 {
 }
Beispiel #8
0
 public sealed override void Build(Build build, Environment env, CancellationToken taskCancelToken, FailedBuildTokenSource failedBuildTokenSource, LoggerList loggers)
 {
     foreach (BuildStep step in BuildSteps)
     {
         step.Apply(env, failedBuildTokenSource, loggers);
         CheckIfBuildCanceled(taskCancelToken, build, loggers.GetLogger <JobBuildLogger.JobBuildLogger>());
         failedBuildTokenSource.Token.ThrowIfFailed();
     }
 }
Beispiel #9
0
 public sealed override void Apply(Environment env, Parameter[] parameters, FailedBuildTokenSource failedBuildTokenSource, LoggerList loggers)
 {
     env.Properties.Add("node", parameters.Single(o => o.Name == "label").Value);
 }