Elliot Blackburn
Elliot Blackburn

Reputation: 4164

Pulling NuGet package version from TeamCity build number using FAKE

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".

Upvotes: 0

Views: 213

Answers (2)

DaveShaw
DaveShaw

Reputation: 52798

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.

Upvotes: 3

Cygnus X-1
Cygnus X-1

Reputation: 53

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"

Upvotes: 1

Related Questions