forked from Inedo/inedox-teamcity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeployTeamCityBuildRecipe.cs
87 lines (73 loc) · 3.75 KB
/
DeployTeamCityBuildRecipe.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.Linq;
using Inedo.BuildMaster;
using Inedo.BuildMaster.Data;
using Inedo.BuildMaster.Extensibility.Recipes;
using Inedo.BuildMaster.Web;
namespace Inedo.BuildMasterExtensions.TeamCity
{
[RecipeProperties(
"Deploy TeamCity Build",
"An application that captures a build artifact from TeamCity and deploys through multiple environments",
RecipeScopes.NewApplication)]
[CustomEditor(typeof(DeployTeamCityBuildRecipeEditor))]
public sealed class DeployTeamCityBuildRecipe : RecipeBase, IApplicationCreatingRecipe, IWorkflowCreatingRecipe
{
public string ApplicationGroup { get; set; }
public string ApplicationName { get; set; }
public int ApplicationId { get; set; }
public string WorkflowName { get; set; }
public int[] WorkflowSteps { get; set; }
public int WorkflowId { get; set; }
public string BuildConfigurationId { get; set; }
public string ArtifactName { get; set; }
public string BuildConfigurationName { get; set; }
public override void Execute()
{
string deployableName = this.ApplicationName;
int deployableId = Util.Recipes.CreateDeployable(this.ApplicationId, deployableName);
int firstEnvironmentId = this.WorkflowSteps[0];
var template = new TeamCityBuildImporterTemplate()
{
ArtifactName = this.ArtifactName,
ArtifactNameLocked = false,
BuildConfigurationId = this.BuildConfigurationId,
BuildNumber = "lastSuccessful",
BuildConfigurationDisplayName = this.BuildConfigurationName
};
Util.Recipes.CreateBuildStepBuildImporter(this.WorkflowId, template);
int firstDeploymentPlanId = Util.Recipes.CreateDeploymentPlanForWorkflowStep(this.WorkflowId, 1);
int stepSequence = 2;
foreach (int step in this.WorkflowSteps.Skip(1))
Util.Recipes.CreateDeploymentPlanForWorkflowStep(this.WorkflowId, stepSequence++);
int actionGroupId = Util.Recipes.CreateDeploymentPlanActionGroup(
firstDeploymentPlanId,
deployableId: null,
deployableName: null,
name: "Stop Application",
description: "Stop/shutdown/disable the application or application servers prior to deployment."
);
actionGroupId = Util.Recipes.CreateDeploymentPlanActionGroup(
firstDeploymentPlanId,
deployableId: deployableId,
deployableName: null,
name: "Deploy " + deployableName,
description: "Deploy the artifacts created in the build actions, and then any configuration files needed."
);
Util.Recipes.AddAction(actionGroupId, 1, Util.Recipes.Munging.MungeCoreExAction(
"Inedo.BuildMaster.Extensibility.Actions.Artifacts.DeployArtifactAction", new
{
ArtifactName = Util.Path2.GetFileName(this.ArtifactName),
DoNotClearTargetDirectory = false
})
);
Util.Recipes.CreateDeploymentPlanActionGroup(
firstDeploymentPlanId,
deployableId: null,
deployableName: null,
name: "Start Application",
description: "Start the application or application servers after deployment, and possibly run some post-startup automated testing."
);
Util.Recipes.CreateSetupRelease(this.ApplicationId, Domains.ReleaseNumberSchemes.MajorMinor, this.WorkflowId, new[] { deployableId });
}
}
}