Pages

Men

rh

10/28/2014

Trigger Release from build with Release Management for Visual Studio 2013 Update 3

To trigger a release from build with Release Management for Visual Studio 2013 Update 2, you needed to install RM client on TFS build agent machine.  With Update 3, this is no longer needed. Release Management Update 3 has exposed some REST APIs to trigger release from TFS build agent machine without installing RM client. You can now write ps script using these REST APIs. You can then include this ps script in post build activity of build definition, to trigger a release with a new successful build. 
The APIs InitiateReleaseFromBuild and InitiateRelease can be used to trigger a release. Both these APIs return releaseId for that release. You can use this releaseId to get release status or Stop or Abandon the release.
If release definition has “Build with Application” or “Build Independently” component, the following API can be used to trigger release for that release definition from build definition.
1. http://RMSERVER:PortNumber/account/releaseManagementService/_apis/releaseManagement/OrchestratorService/
InitiateReleaseFromBuild?teamFoundationServerUrl=”tfsserverurl"&teamProject="project"&buildDefinition="definition"
&buildNumber="build”&targetStageName="targetStage
If release definition has “Builds externally” components, the followoing API can be used to trigger a release for a given release definition from build definition.
2. http://RMSERVER:PortNumber/account/releaseManagementService/_apis/releaseManagement/OrchestratorService/
InitiateRelease?releaseTemplateName="releaseDefinition"&deploymentPropertyBag="propertyBag"&api-version=2.0

Here are other APIs which can be used to get additional details w.r.t. a release. Note that these take a releaseId which is output of the above APIs.
3. http://RMSERVER:PortNumber/account/releaseManagementService/_apis/releaseManagement/OrchestratorService/
AbandonRelease?releaseId=releaseId&api-version=2.0
4. http://RMSERVER:PortNumber/account/releaseManagementService/_apis/releaseManagement/OrchestratorService/
StopRelease?releaseId=releaseId&api-version=2.0
5. http://RMSERVER:PortNumber/account/releaseManagementService/_apis/releaseManagement/OrchestratorService/
ReleaseStatus?releaseId=releaseId&api-version=2.0
(Note: the above urls are put in 2-3 lines for readability. Read them as 1 line API) 

You can find an attached sample script in the zip file named InitiateReleaseFromBuild.ps1, which takes RMserver, port number, teamproject and targetStage as parameters and triggers a release. Once release is triggered, it will wait till the release state changes from In progress to Released / Rejected state.
The following snapshot showcases the way to call InitiateReleaseFromBuild.ps1 from build definition:

The modified build template TfvcTemplate.12.2.xaml is attached, for reference.
You can modify this script to trigger releases on multiple RM servers using same build. You can also add logic to abandon a release after a particular interval of time if the release does not complete.  If you wish to fail a build if release fails, you should exit the powershell script with return value 1 upon failure. Exit with return value 0 to pass the build even on release failure.
 Source from
http://blogs.msdn.com/b/visualstudioalm/archive/2014/10/10/trigger-release-from-build-with-release-management-for-visual-studio-2013-update-3.aspx

No comments :

Post a Comment