0
votes

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!

1
Why do you want to put binaries in source control? This is considered a bad practice. If you explain what your goal is, someone might be able to recommend a better solution.Daniel Mann
Hi, the only reason is we just need to store all binaries in some central location which is accessible to everyone. So my team lead suggested to go and store them at VSTS repository.Yashwanth Chakka
You can publish your artifacts and then they will be attached to the build. Or you can push your builds to a package management feed.Daniel Mann

1 Answers

1
votes

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).