There are two projects eg. Project1 and Project2. Now In project2, we need to create a release definition,in which we need to copy build output of project1's build definition.
Problem is that we could not give artifact as that of Project1 build definition in Project2 release.
If we could access the $(Build.BuildNumber) variable of project1 from Project2, prolem will be solve.
Please suggest.
Thank you.
You can access the build number via REST API, simple steps:
Code:
Param(
[string]$teamProject,
[string]$collectionURL,
[string]$buildId,
[string]$userName,
[string]$password
)
$basicAuth = ("{0}:{1}" -f $userName,$password)
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = @{Authorization=("Basic {0}" -f $basicAuth)}
$url="$($collectionURL)$($teamProject)/_apis/build/builds/$($buildId)?api-version=2.0"
Write-Output $url
Function GetBuildNumber{
$result = Invoke-RestMethod -Uri $url -headers $headers -Method Get
Write-Output $result.buildNumber
Write-Host "##vso[task.setvariable variable=anotherBuildNumber;]$($result.buildNumber)"
}
GetBuildNumber
Add PowerShell task to your release definition.
Script filename:[your powershell script file in artifact, e.g. $(System.DefaultWorkingDirectory)/PowerShellVnext/TFS2015U2Solution/PowerShellModuleProject1/RestTest.ps1];
Arguments: -teamProject $(teamProject) -collectionURL $(System.TeamFoundationCollectionUri) -buildId $(buildId) -userName $(username) -passwor $(password)
After that the build number value is stored in anotherBuildNumber variable.