My build pipeline gets sources in the local sources folder via "Get sources". I would like to get some other files from a different project.
I tried:
$collection = "well my collection..."
$tfsProjectTargetPath = "`$/projectB/subdir/branch"
$localWorkDir = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
$workspaceName = $env:Build_Repository_Tfvc_Workspace
& $tf vc workfold /map /workspace:$workspaceName $localWorkDir /collection:$collection /noprompt
That runs into "TF14061: The workspace ws_XXX_YYYY;user does not exist."
.
I also tried creating a new workspace:
$workspaceName = "some new name"
& $tf vc workspace /new /location:local /permission:Public $workspaceName /collection:$collection /noprompt
That runs into "The path ..\w\220\s\projectA\subidr\branch is already mapped in workspace ws_XXX_YYYY;Build\<guid>"
.
To me it seems the value of $workspaceName + user is the issue. Somehow the $workspaceName is coupled to a "build:" user. My powershell runs with a different user than the workspace.
Any suggestions or ideas?
I found the solution:
<workspacename>;Build\<collectionId>
In Powershell, getting files from another project can be achieved with:
$tf = [System.IO.Path]::Combine($env:AGENT_HOMEDIRECTORY, "externals", "tf", "tf.exe")
$workspaceName = $env:Build_Repository_Tfvc_Workspace
$workspaceNameWithUser = $workspaceName + ";Build\" + $env:SYSTEM_COLLECTIONID
& $tf vc workspace /delete $workspaceNameWithUser
Now you can create a new workspace and a new mapping, like I mentioned in my question:
$collection = "well my collection..."
$tfsProjectTargetPath = "`$/projectB/subdir/branch"
$localWorkDir = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
$workspaceName = "choose a new name"
& $tf vc workspace /new /location:local /permission:Public $workspaceName /collection:$collection /noprompt $commandLogin
& $tf vc workfold /unmap /workspace:$workspaceName $/ /collection:$collection /noprompt $commandLogin
& $tf vc workfold /map /workspace:$workspaceName $tfsProjectTargetPath $localWorkDir /collection:$collection /noprompt
& $tf vc get /recursive /overwrite $localWorkDir /noprompt