당신은 (는 API 버전 api-version=2.3-preview.1
으로) 그것을 달성하기 위해 REST API를 사용하여 요구하는 것 같다 내가 테스트
을 PS 스크립트 아래의 TFS 2015 업데이트 4 (Version 14.114.26403.0
)에서 예상대로 작동합니다. (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
배포 특정 환경에 방출 :은 (세 번째 환경을 배포
새로운 릴리스 만들기 : 당신의 참고를위한 PowerShell 스크립트 아래
이 샘플에서는 요구 사항에 따라 변경하십시오.)
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
함께 가져와 새 릴리스를 만들고 특정 환경을 하나의 스크립트로 배포 할 수도 있습니다. 내 대답은 another thread입니다.
감사합니다. 매우 도움이되었습니다. 정확히 필요한 것 같습니다. – sam