2017-10-10 71 views

回答

0

你需要获得特定发布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 

enter image description here

+0

感谢Andy-MSFT。它的工作。 – user3744418

相关问题