Reputation: 3986
How do I execute another FAKE build script from within a FAKE build script?
I want to create a build script which clones a git repo and then executes a build script within the cloned project. After that it should tag the branch and publish the build artifact to a Nexus Repository Manager.
Also I want to hand over some parameter to the external build script, e.g. a version tag.
Here is some pseudo code:
Target "ReleaseBuild" (fun _ ->
CleanDir "src"
cloneSingleBranch "" "http://<URL to git-repo>" "master" "src"
????? "src/build.fsx" versionNumer
... tagging etc. ...
)
Upvotes: 0
Views: 158
Reputation: 80744
The usual way to modularize your build is not by calling FAKE within FAKE, but by having FSI load modules using the #load
directive.
For example:
// build.fsx
#r "path/to/FakeLib.dll"
#load "./OtherModule.fsx"
open Fake
Target "ReleaseBuild" <| fun _ ->
CleanDir "src"
cloneSingleBranch "" "http://<URL to git-repo>" "master" "src"
OtherModule.DoWhatever versionNumer
...
// OtherModule.fsx
let DoWhatever version =
...
.
EDIT (in response to comment)
If the other script file doesn't exist when the first one starts, then you could execute it using FSIHelper.executeFSI
:
Target "ReleaseBuild" <| fun _ ->
CleanDir "src"
cloneSingleBranch "" "http://<URL to git-repo>" "master" "src"
let result, messages = FSIHelper.executeFSI "src" "build.fsx" []
...
(or executeFSIWithArgs
if you need to pass arguments)
If even this doesn't work for you for some reason, I would just resort to executing it as a regular shell command, using Shell.Exec
:
Target "ReleaseBuild" <| fun _ ->
CleanDir "src"
cloneSingleBranch "" "http://<URL to git-repo>" "master" "src"
let errCode = Shell.Exec ("path/to/fake.exe", args = "src/build.fsx")
...
But if you want this to be cross-platform, it gets a bit complicated: *.exe
won't execute natively on UNIX, you need to run mono
and give the .exe
file as argument. To work around that, you'd need to wrap fake.exe
in a shell script (two scripts - one for Windows, one for UNIX), and then pass the name of that script as argument into the FAKE script.
Upvotes: 1