können Sie die REST-API verwenden, um das zu erreichen (mit der API-Version api-version=2.3-preview.1
):
I getestet auf TFS 2015 Update 4 (Version 14.114.26403.0
) mit unter PS-Skripten funktioniert es wie erwartet.
Below Powershell-Skripte für Ihre Referenz:
Erstellen Sie ein neues Release: (Siehe REST API here)
Param(
[string]$collectionurl = "http://server:8080/tfs/Collection",
[string]$projectName = "ProjectName",
[string]$keepForever = "true",
[string]$user = "username",
[string]$token = "token",
[string]$releasedDefinitionId = "2"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
function CreateJsonBody
{
$value = @"
{
"definitionId":$releasedDefinitionId,
"description":"",
"artifacts":[
{
"alias":"VSTEST",
"instanceReference":{
"name":"20171123.1",
"id":"1256",
"sourceBranch":"$/0418Scrum/web0418"}
}],
"isDraft":false,
"manualEnvironments":[]
}
"@
return $value
}
$json = CreateJsonBody
$uri = "$($collectionurl)/$($projectName)/_apis/Release/releases?api-version=2.3-preview.1"
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$ReleaseID = $result.id
Write-Host "ReleaseID:" $ReleaseID
Deploy die Freisetzung in einer bestimmten Umgebung: (Bereitstellen der dritten Umgebung In diesem Beispiel, ändern Sie es einfach basierend auf Ihrer Anforderung.)
Param(
[string]$baseurl = "http://server:8080/tfs/CollectionLC",
[string]$projectName = "ProjectName",
[string]$keepForever = "true",
[string]$user = "username",
[string]$token = "token",
[string]$ReleaseID = "3"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
#Get releaseresponse
$Releaseurl= "$baseurl/$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 = "$baseurl/$projectName/_apis/release/releases/$releaseid/environments/"+$thirdEnvironment+"?api-version=2.3-preview.1" # 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
Sie können sie auch zusammen erstellen, eine neue Version erstellen und die spezifische Umgebung in einem Skript bereitstellen. Siehe meine Antwort in another thread.
Danke, sehr hilfreich, das sieht genau so aus, wie wir es brauchen! – sam