0
votes

I've created my build script that generates a NuGet package from my project and I'm now trying to pull the version number from TeamCity rather than using a static value inside my script.

My current code is like this (within a Target)

NuGet (fun p ->
    {p with
        Authors = authors
        Project = projectName
        Description = projectDescription
        OutputPath = packagingRoot
        Summary = projectSummary
        WorkingDir = packagingDir
        Version = TeamCityHelper.TeamCityBuildNumber }) "myProject.nuspec"

The problem is that the TeamCity helper that comes bundled with FAKE returns an optional string instead of a string, where as the NuGet call takes a string.

This is my first time using F#, how would I go about getting TeamCityHelper.TeamCityBuildNumber as a string and not an optional so it's ready for the NuGet step? Preferably I'd like to kill the build if nothing is returned from TeamCity for the version number, but for now I'd like to just throw in a place holder of something like "0.0.1".

2
What do you want the version number to be if there is nothing returned from Team City? - DaveShaw
@DaveShaw I've edited my question to include this. Preferably I'd like to fail the build but for now I'm looking to just use a place holder of something like "0.0.1" while I get other components of the CI server set up. - Elliot Blackburn

2 Answers

3
votes

I'd just create a function like this one below and place it above your NuGet target:

let getTeamCityBuildNumberOrDefault() =
    match TeamCityHelper.TeamCityBuildNumber with
    | Some v -> v
    | None -> "0.0.1"

Then use it in place of TeamCityHelper.TeamCityBuildNumber in your NuGet target.

1
votes

have you tried something like :

NuGet (fun p ->
    match TeamCityHelper.TeamCityBuildNumber with 
    | Some(buildNumber) ->
        {p with
            Authors = authors
            Project = projectName
            Description = projectDescription
            OutputPath = packagingRoot
            Summary = projectSummary
            WorkingDir = packagingDir
            Version = buildNumber}
    | None ->
        {p with
            Authors = authors
            Project = projectName
            Description = projectDescription
            OutputPath = packagingRoot
            Summary = projectSummary
            WorkingDir = packagingDir
            Version = "0.0.1"}) "myProject.nuspec"