简体   繁体   中英

How to get current Build definition name using PowerShell in TFS

We are using TFSdeployer to trigger Build deployment to deploy build.

But stuck with how to get Build definition of the current Build for which we trying and could not succeed.

How to get current Build definition name using below PowerShell script instead of hardcode.

Scenario: If i trigger from Test1 BuildQuality then first code should be working . If i trigger from Test2 BuildQuality then second code should be working. (If-Else code is working perfectly)

Tried using $TFSDeployerBuildDetail.DefinitionName $Build.Name

But that seems to be not working, Any help is appreciated.

$BuildDefinitionName =  "Test1"
$PackagePath = "C:\extra\Package_Files"
$DestPath1 ="C:\extra\Test1"
$DestPath2 ="C:\extra\Test2"
$logFile ="C:\extra\logs"
$utilPath = "C:\util\"


if ($BuildDefinitionName -eq "Test1")
{

Write-Host "Testing 1st Copy"

Add-Content -Path $logFile "Copying to Test1"
& $utilPath\robocopy $PackagePath $DestPath1 /s >> $logFile

}

elseif($BuildDefinitionName -eq "Test2")
{

Write-Host "Testing 2nd Copy"
Add-Content -Path $logFile "Copying to Test2"
& $utilPath\robocopy $PackagePath $DestPath2 /s >> $logFile

}

Use the provided environment variable:

$env:BUILD_DEFINITIONNAME

https://docs.microsoft.com/en-us/vsts/build-release/actions/scripts/powershell

Since you indicated you're using XAML build , the environment variable would be $env:TF_BUILD_BUILDDEFINITIONNAME .

The other answer is correct for the newer, web-based build system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM