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)); } }
protected void CheckIfBuildCanceled(CancellationToken taskCancelToken, Build build, JobBuildLogger logger, Action action = null) { //Verify if the build was cancelled if (taskCancelToken.IsCancellationRequested) { logger.Log(new Log("Cancelled at " + DateTime.Now)); action(); build.Status = "Cancelled"; taskCancelToken.ThrowIfCancellationRequested(); } }