0
我在使用CD的前提下使用TFS 2017。我正尝试使用PowerShell重新部署发行版。有没有API来重新部署发布?如何在PowerShell中使用api重新部署TFS版本
我在使用CD的前提下使用TFS 2017。我正尝试使用PowerShell重新部署发行版。有没有API来重新部署发布?如何在PowerShell中使用api重新部署TFS版本
你需要获得特定发布ID,并通过REST API的环境ID,然后调用REST API重新部署旧版本。
您可以使用以下PowerShell脚本重新部署具体的发布环境:
Param(
[string]$Collecitonurl = "http://server:8080/tfs/DefaultCollection",
[string]$projectName = "YouTeamProjectName",
[string]$keepForever = "true",
[string]$user = "Domain\User",
[string]$token = "your token",
[string]$releaseid = "45" # Give the specific Release ID here
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
#Get releaseresponse
$Releaseurl= "$Collecitonurl/$projectName/_apis/Release/releases/$releaseid"
$releaseresponse = Invoke-RestMethod -Method Get -UseDefaultCredentials -ContentType application/json -Uri $Releaseurl
#Get all of the environment IDs from the release response:
$environmentIDs = $releaseresponse.environments.ForEach("id")
#Get the specific environment ID by grabbing the element in the environment IDs array:
$firstEnvironment = $environmentIDs[0]
$secondEnvironment = $environmentIDs[1]
$thirdEnvironment = $environmentIDs[2] # ...
#Create the JSON body for the deployment:
$deploymentbody = @"
{"status": "inprogress"}
"@
#Invoke the REST method to redeploy the release:
$DeployUrl = "$Collecitonurl/$projectName/_apis/release/releases/$releaseid/environments/"+$firstEnvironment+"?api-version=3.2-preview" # Change the envrionment ID accordingly based on your requirement.
$DeployRelease = Invoke-RestMethod -Method Patch -ContentType application/json -Uri $DeployUrl -Headers @{Authorization=("Basic {0}" -f $base64authinfo)} -Body $deploymentbody
write-host "environmentIDs:" $environmentIDs
感谢Andy-MSFT。它的工作。 – user3744418
你所说的 “重新部署” 是什么意思?针对旧版本运行新版本?重新运行旧版本? –
@ DanielMann,是的。重新运行旧版本 – user3744418