I've release definition which has more than environment (QA, Stage...). Within environment, I've agent phase. Within agent phase, I've task group. Initially, the release definition is having trigger option (QA - auto, Stage - manual). What I've trying to do is:
Download release definition
Update release definition (just change the trigger option for Stage environment from manual to auto)
Import release definition.
After I downloaded, updated and import release definition, the agent phase name is automatically changed to the same name as environment, and the task group is lost. I went to history and do a diff, I see the agent phase name is changed and entire Workflowtask section is gone for all environment. I checked json file that I downloaded and updated, and it does have workflowtask section. Am I missing something or this is a bug? Below is my powershell script. Please advise.
$releaseuri = $tpcUri + "/" + $teamprojectname + "/_apis/Release/definitions/" + $releaseid # + "?api-version=4.0-preview.3"
Write-Host $releaseuri
$releasetemplate = $downloadlocation + "\" + $releasetemplatename
Write-Host $releasetemplate
# Get release definition and save to local computer
$Jsonfile = Invoke-RestMethod -Uri $releaseuri -Method Get -UseDefaultCredentials
$Jsonfile | ConvertTo-Json -depth 100 | Out-File $releasetemplate
$ReleaseFile = "C:\DevOps\updatedmytest1.json"
#import release definition
$Uri = $tpcUri + "/" + $teamprojectname + "/_apis/release/definitions?api-version=3.0-preview.2"
Write-Verbose "URI: $uri"
Write-Host "Importing release definition........"
$release = gc $ReleaseFile -Raw -ea Stop
$result = Invoke-RestMethod -Method Post -UseDefaultCredentials -ContentType application/json -Uri $Uri -Body $release
Best Regards, Andy Pham
According to this part in your code:
$Uri = $tpcUri + "/" + $teamprojectname + "/_apis/release/definitions?api-version=3.0-preview.2"
Please use another version of your Rest API version instead of 3.0-preview.2
. This issue should be the Rest API version you are using.
According to the tutorials in MSDN:
api-version
Required. Version of the API to use. This should be set to '4.0-preview.3' to use this version of the API.
Also take a look at this similar question: TFS 2017 Update1: Programmatically updating TFS Release Definitions removes server phase (manual intervention)