Created
September 1, 2017 10:31
-
-
Save ukcoderj/38f37fd23000aeb630f97da22138c986 to your computer and use it in GitHub Desktop.
Powershell Check Out / In Document from VSTS (TFS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-PSSnapin Microsoft.TeamFoundation.PowerShell | |
# This file requires the TFS Power Tools (2015+). When installing, you must select Custom Installation and select PowerShell Cmdlets | |
# *VSTS Login* | |
# YOU MUST go to 'Options' and turn on 'Allow scripts to access OAuth token' for the buld | |
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/definitions/$($env:SYSTEM_DEFINITIONID)?api-version=2.0" | |
Write-Host "URL: $url" | |
$definition = Invoke-RestMethod -Uri $url -Headers @{ | |
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" | |
} | |
Write-Host "Definition = $($definition | ConvertTo-Json -Depth 100)" | |
"***************** Authenticated *****************" | |
" *VSTS Check Out file* from $fileToUpdate" | |
Add-TfsPendingChange -Edit -Item $fileToUpdate -Verbose -ErrorAction Stop -wa 0 | |
# read the file, update the number and save it back | |
$stuff = Get-Content $fileToUpdate | |
# modify stuff - make sure you actually make a change! | |
Set-Content -Value $stuff -Path $fileToUpdate | |
# *VSTS Check In* Check in the file after changes. | |
" *VSTS Check In" | |
New-TfsChangeset -Item $fileToUpdate -Verbose -Comment "***NO_CI***" -Override true -ErrorAction Stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment