2017-10-10 14 views

Répondre

0

Vous devez obtenir le ID spécifique de sortie et l'ID Environnement via REST API, puis appelez l'API REST pour redéployer l'ancienne version.

Vous pouvez utiliser le script ci-dessous PowerShell pour redéployer l'environnement de sortie spécifique:

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

Merci Andy-MSFT. ça marche. – user3744418