Yashwanth Chakka
Yashwanth Chakka

Reputation: 1

VSTS: Publish build artifacts to remote repository TFVC

Is it possible to publish the outputs from a build pipeline (artifacts) on visual studio team service to the repository? Our repo is being hosted in VSTS and we are using TFVC (team foundation version control to store our code).

I have used out of box copy & publish tasks but it didn't work.

Greatly appreciate your response!

Upvotes: 0

Views: 421

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41775

Like Daniel said, this is considered a bad practice, but if you still want it you can do it with a PowerShell script:

Param(
[string]$tfvcRepoPath
)
$artifactsFolderPath = "$($env:Agent_BuildDirectory)\newCode"
$tempWorkspacePath =  "$($env:Agent_BuildDirectory)\tempWorkspace"

New-Item -Path $artifactsFolderPath-ItemType directory

Copy-Item -Path "$($env:Build_ArtifactStagingDirectory)/*" -Recurse -Destination $artifactsFolderPath

New-Item -Path $tempWorkspacePath -ItemType directory

cd $tempWorkspacePath 

$tfExe = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe"

& $tfExe workspace /collection:{TfsCollection} /new "TempWorkspace" /noprompt

& $tfExe workfold "$($tfvcRepoPath)" $tempWorkspacePath 

Copy-Item -Path "$($artifactsFolderPath)/*" -Recurse -Destination $tempWorkspacePath 

& $tfExe add * /recursive /noignore

& $tfExe checkin /recursive /comment:"artficats after build"

& $tfExe workspace /delete /collection:{TfsCollection} "Tempworkspace"

cd c:/
Remove-Item -Path $newCodeFolderPath -Force -Recurse
Remove-Item -Path $tempWorkspacePath -Force -Recurse

Change the $tfExe = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe" regarding your installed Visual Studio version (I used the path for VS 2017 Professional edition).

Upvotes: 1

Related Questions