Albacore / albacore

Albacore is a professional quality suite of Rake tasks for building .NET or Mono based systems.
www.albacorebuild.net
221 stars 64 forks source link

Detection of build failures? #242

Closed logiclrd closed 6 years ago

logiclrd commented 6 years ago

Hello :-) I'm writing this here because I figure there'll be some people with excellent domain knowledge reading it. I'm still learning about Ruby and Rake tasks.

What I'm trying to figure out is, how are build failures detected? I did some snooping, and I see that Albacore::Build::Cmd just calls system on the command-line it has built up. This means that that line will have a true return value for a 0 exit code and false otherwise -- so a failed build will return false. This false value gets propagate back up to the level of the Rake task. But, then I looked into how Rake invokes tasks, and from the source code I saw in the Rake documentation, it looks like it completely ignores return values. They get subsumed in a block passed to @actions.each, and the return value of @actions.each seems to be @actions itself. So, Rake tasks do not have return values.

Where in this flow, then, does a build error get detected? Should Albacore be throwing an exception when system returns false? Or is there some underlying mechanic I'm completely missing that already detects build failures in this circumstance?

What set me on this journey is that I have another project that must invoke multiple different builds from within a single build definition. To do that, I use statements such as this:

Rake::Task['msbuild'].execute(:project_variables => VARIABLES[:build][:project_name])

The :msbuild task in this case is a task defined using Albacore's build DSL. All it does is copy parameters from the :project_variables passed into it into the Albacore::Build::Cmd configuration object that the build DSL passes in.

In my build output, what I am seeing is that Albacore is successfully launching MSBuild, and then MSBuild is emitting errors (due to a configuration problem in the environment) -- but the build isn't being detected as a failure. The Ruby script is returning successfully at the top level, and the build is green in our automation software.

What am I overlooking here?

logiclrd commented 6 years ago

Okay, I have done more investigation and discovered that Albacore overrides Ruby's system with its own (in cross_platform_cmd.rb). Its override raises an exception if anything is sent to stderr. So, that explains how build failures are normally caught (though the fact that it is redefining a core function with the same name is a bit confusing; it isn't immediately obvious at the call site that it isn't using the standard system function).

This still leaves unexplained the fact that the build system didn't detect a failure, but that might be out of scope for Albacore, because the build output is in fact showing a stack trace for an unhandled exception, even though the build ends up still being reported a success. Time to try to find some unneeded rescue block I guess... :-)