How can one determine if a csproj is being run on a TFS build agent?

前端 未结 4 1793
小鲜肉
小鲜肉 2021-02-07 19:31

We use TFS 2010.

There are a couple of projects with deployment steps which must know whether they are running on a dev machine or on the TFS build agent.

Right

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 20:06

    I thought to provide my own answer updated to 2020.

    The way we do it is by checking an environment variable, because TFS (now Azure DevOps) exposes build variables through the environment. When tested in msbuild code they look the same build variables passed on the msbuild command line, but we also employ powershell scripts, which rely only on the environment.

    Also, I would sometimes like to distinguish between the Build and the Release pipeline, because in the classic Release pipeline (as opposed to yaml, which we do not have on prem) some things do not work the same (like vsts logging commands)

    So, here is what we are using:

    • BUILD_BUILDNUMBER - exists in both build and release, because all of our releases include a build artifact
    • RELEASE_ENVIRONMENTNAME - exists only in the classic release pipeline
    • TF_BUILD - not sure if exists in release, definitely in build

    I would not bother with BuildingInsideVisualStudio, because it is false when build with msbuild on the command line, yet it is not a build on the CI server.

提交回复
热议问题