Skip to content

Commit bfcb8a4

Browse files
committed
Merge pull request Azure#1673 from aneillans/dev
Ability to parse "Tokens" in SetParameters file as per release management
2 parents ee88241 + ab170f3 commit bfcb8a4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/ServiceManagement/Services/Commands/Websites/PublishAzureWebsiteProject.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class PublishAzureWebsiteProject : WebsiteContextBaseCmdlet, IDynamicPara
2828
[ValidateNotNullOrEmpty]
2929
public Hashtable ConnectionString { get; set; }
3030

31+
[Parameter(ParameterSetName = "Package", Position = 3, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration tokens to use for the deployment.")]
32+
[ValidateNotNullOrEmpty]
33+
public string Tokens { get; set; }
34+
3135
[Parameter(Mandatory = false, ParameterSetName = "Package", HelpMessage = "The WebDeploy SetParameters.xml file to transform configuration within the package.")]
3236
public string SetParametersFile { get; set; }
3337

@@ -83,6 +87,33 @@ public override void ExecuteCmdlet()
8387
}
8488
}
8589

90+
if (!File.Exists(fullSetParametersFile))
91+
{
92+
if (File.Exists(Path.Combine(Path.GetDirectoryName(fullPackage), fullSetParametersFile)))
93+
{
94+
WriteVerbose("Setting path for Parameters file to local one to package: " + Path.Combine(Path.GetDirectoryName(fullPackage), fullSetParametersFile));
95+
fullSetParametersFile = Path.Combine(Path.GetDirectoryName(fullPackage),fullSetParametersFile);
96+
}
97+
}
98+
99+
// If tokens are passed in, update the parameters file if there is one
100+
if (!string.IsNullOrEmpty(Tokens) && !string.IsNullOrEmpty(fullSetParametersFile))
101+
{
102+
// Convert tokens string to hashtable
103+
string[] tokenSplit = Tokens.Split(';');
104+
105+
WriteVerbose(string.Format("Replacing tokens in {0}", fullSetParametersFile));
106+
var fileContents = File.ReadAllText(fullSetParametersFile);
107+
108+
foreach (string pair in tokenSplit)
109+
{
110+
string[] data = pair.Split('=');
111+
fileContents = fileContents.Replace(string.Format("__{0}__", data[0].Replace("\"", "")), data[1].Replace("\"", ""));
112+
}
113+
114+
File.WriteAllText(fullSetParametersFile, fileContents);
115+
}
116+
86117
try
87118
{
88119
// Publish the package.

0 commit comments

Comments
 (0)