Fixing the ZIP Deploy Task to allow publishing to Functions slots

This commit is contained in:
Brian Zhu 2018-06-12 18:05:52 -07:00 коммит произвёл Ahmed ElSayed
Родитель 76031aa635
Коммит 2c84f33f3e
2 изменённых файлов: 10 добавлений и 10 удалений

Просмотреть файл

@ -42,8 +42,8 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
<ZipDeployTask
ZipToPublishPath="$(ZippedPublishContentsPath)"
DeploymentUsername="$(UserName)"
DeploymentPassword="$(Password)"
SiteName="$(DeployIisAppPath)" />
DeploymentPassword="$(Password)"
ScmSiteUrl="$(ScmSiteUrl)" />
</Target>
</Project>

Просмотреть файл

@ -21,35 +21,35 @@ namespace Microsoft.NET.Sdk.Functions.Tasks
public string DeploymentPassword { get; set; }
[Required]
public string SiteName { get; set; }
public string ScmSiteUrl { get; set; }
public override bool Execute()
{
using(DefaultHttpClient client = new DefaultHttpClient())
{
System.Threading.Tasks.Task<bool> t = ZipDeployAsync(ZipToPublishPath, DeploymentUsername, DeploymentPassword, SiteName, client);
System.Threading.Tasks.Task<bool> t = ZipDeployAsync(ZipToPublishPath, DeploymentUsername, DeploymentPassword, ScmSiteUrl, client);
t.Wait();
return t.Result;
}
}
private async System.Threading.Tasks.Task<bool> ZipDeployAsync(string zipToPublishPath, string userName, string password, string siteName, IHttpClient client)
private async System.Threading.Tasks.Task<bool> ZipDeployAsync(string zipToPublishPath, string userName, string password, string scmSiteUrl, IHttpClient client)
{
if (!File.Exists(ZipToPublishPath) || client == null)
{
return false;
}
string url = $"https://{siteName}.scm.azurewebsites.net/api/zipdeploy";
string zipDeployPublishUrl = scmSiteUrl + "/api/zipdeploy";
Log.LogMessage(MessageImportance.High, String.Format(Resources.PublishingZipViaZipDeploy, zipToPublishPath, url));
Log.LogMessage(MessageImportance.High, String.Format(Resources.PublishingZipViaZipDeploy, zipToPublishPath, zipDeployPublishUrl));
Uri uri = new Uri(url, UriKind.Absolute);
Uri uri = new Uri(zipDeployPublishUrl, UriKind.Absolute);
FileStream stream = File.OpenRead(ZipToPublishPath);
IHttpResponse response = await client.PostWithBasicAuthAsync(uri, userName, password, "application/zip", Encoding.UTF8, stream);
if(response.StatusCode != HttpStatusCode.OK && response.StatusCode == HttpStatusCode.Accepted)
if(response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.Accepted)
{
Log.LogError(String.Format(Resources.ZipDeployFailureErrorMessage, url, response.StatusCode));
Log.LogError(String.Format(Resources.ZipDeployFailureErrorMessage, zipDeployPublishUrl, response.StatusCode));
return false;
}