Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for builds within Team Foundation Server (and VSO). #915

Merged
merged 1 commit into from
Aug 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/app/FakeLib/BuildServerHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Fake.BuildServerHelper

/// The server type option.
type BuildServer =
| TeamFoundation
| TeamCity
| CCNet
| Jenkins
Expand All @@ -29,6 +30,16 @@ let localBuildLabel = "LocalBuild"
/// This output file can be specified by using the *logfile* build parameter.
let mutable xmlOutputFile = getBuildParamOrDefault "logfile" "./output/Results.xml"

/// Checks if we are on Team Foundation
/// [omit]
let isTFBuild =
let tfbuild = environVar "TF_BUILD"
tfbuild <> null && tfbuild.ToLowerInvariant() = "true"

/// Build number retrieved from Team Foundation
/// [omit]
let tfBuildNumber = environVar "BUILD_BUILDNUMBER"

/// Build number retrieved from TeamCity
/// [omit]
let tcBuildNumber = environVar "BUILD_NUMBER"
Expand Down Expand Up @@ -65,6 +76,7 @@ let buildServer =
elif not (isNullOrEmpty travisBuildNumber) then Travis
elif not (isNullOrEmpty appVeyorBuildVersion) then AppVeyor
elif isGitlabCI then GitLabCI
elif isTFBuild then TeamFoundation
else LocalBuild

/// The current build version as detected from the current build server.
Expand All @@ -77,6 +89,7 @@ let buildVersion =
| Travis -> getVersion travisBuildNumber
| AppVeyor -> getVersion appVeyorBuildVersion
| GitLabCI -> getVersion gitlabCIBuildNumber
| TeamFoundation -> getVersion tfBuildNumber
| LocalBuild -> getVersion localBuildLabel

/// Is true when the current build is a local build.
Expand Down
23 changes: 16 additions & 7 deletions src/app/FakeLib/Git/Information.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ let isGitVersionHigherOrEqual referenceVersion =
isVersionHigherOrEqual versionParts referenceVersion

/// Gets the git branch name
let getBranchName repositoryDir =
let getBranchName repositoryDir =
if (repositoryDir = "" || repositoryDir = ".") && buildServer = TeamFoundation then
environVar "BUILD_SOURCEBRANCHNAME"
else
let ok,msg,errors = runGitCommand repositoryDir "status"
let s = msg |> Seq.head

Expand All @@ -37,7 +40,10 @@ let getBranchName repositoryDir =
if startsWith replaceNoBranchString s then noBranch else s.Replace(replaceBranchString,"")

/// Returns the SHA1 of the current HEAD
let getCurrentSHA1 repositoryDir = getSHA1 repositoryDir "HEAD"
let getCurrentSHA1 repositoryDir =
if (repositoryDir = "" || repositoryDir = ".") && buildServer = TeamFoundation then
environVar "BUILD_SOURCEVERSION"
else getSHA1 repositoryDir "HEAD"

/// Shows the git status
let showStatus repositoryDir = showGitCommand repositoryDir "status"
Expand Down Expand Up @@ -74,8 +80,11 @@ let getLastTag() = (describe "").Split('-') |> Seq.head

/// Gets the current hash of the current repository
let getCurrentHash() =
let tmp =
(shortlog "").Split(' ')
|> Seq.head
|> fun s -> s.Split('m')
if tmp |> Array.length > 2 then tmp.[1].Substring(0,6) else tmp.[0].Substring(0,6)
if buildServer = TeamFoundation then
environVar "BUILD_SOURCEVERSION"
else
let tmp =
(shortlog "").Split(' ')
|> Seq.head
|> fun s -> s.Split('m')
if tmp |> Array.length > 2 then tmp.[1].Substring(0,6) else tmp.[0].Substring(0,6)