FAKE Final Targets

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:

  1. Start a new launch (test session) on the server
  2. Execute all tests: unit & integration tests (in my scenario).
  3. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s