Today I discovered a new (for me) FAKE feature called FinalTarget. I worked on integration with our new product ReportPortal (in beta right now) that collects and visualizes test results and faced a problem …
The integration process is the following:
- Start a new launch (test session) on the server
- Execute all tests: unit & integration tests (in my scenario).
- Close a launch on the server
As you see, I need to close a launch even in the case when tests failed. So I cannot stop an execution of build script directly on the failure. Unexpectedly, but FAKE provides an elegant solution for this scenario – FinalTarget (target that will be executed in any case if you activate it).
FAKE dependencies look like this in my script:
"Clean" ==> "RestorePackages" ==> "Build" =?> ("RP_StartNewLaunch", not <| hasBuildParam "skipTests") =?> ("RunUnitTests", not <| hasBuildParam "skipTests") =?> ("RunIntegrationTests", hasBuildParam "allTests") =?> ("RP_FinishLaunch", not <| hasBuildParam "skipTests") ==> "All"
Targets look like this:
Target "RP_StartNewLaunch" (fun _ -> ... ActivateFinalTarget "RP_FinishLaunch" ) FinalTarget "RP_FinishLaunch" (fun _ -> ... ) Target "RunUnitTests" (fun _ -> ... ) Target "RunIntegrationTests" (fun _ -> ... )
As you see, I defined FinalTarget instead of usual Target for “RP_FinishLaunch” and activated it on start of a new launch.
FAKE is awesome 😉
One thought on “FAKE Final Targets”