持续部署和放大器;交货 [英] Continuous deployment & delivery

查看:110
本文介绍了持续部署和放大器;交货的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个包含+10项目,从其中2名是网站的解决方案。现在我需要设置链接到我们的TFS服务器构建定义(S),即构建解决方案,并部署2处向右Azure的网站。我已经尝试了几种不同的方法,但发货似乎每一次失败。 TFS的服务器上建立的项目是没有问题的,但是当需要蔚蓝交付正确的ASP项目,以正确的Azure的网站,它失败......任何人都可以点我在正确的方向上如何创建这样一个构建定义,并在指定交付选项?

We have a solution that contains +10 projects, from whom 2 are websites. Now i need to setup a build definition(s) linked to our TFS server, that builds the solution and deploys the 2 sites to the right Azure website. I've tried a few different approaches, but the delivery seems to fail every time. Building the project on the TFS server is no problem, but when azure needs to deliver the right asp project, to the correct Azure website, it fails... Can anybody point me in the right direction on how to create such a build definition, and where to specify the delivery options?

编辑:

要说明从我们构建的图像。

To illustrate with an image from our build.

因此​​,我们必须在此文件夹中的2个网站:

So we have 2 websites in this folder:

我想这个文件夹在这两个网站发布到正确的位置蔚蓝。
是否有人知道一个很好的方法来实现与2个网站一succesfull不断交付?

I'd like to publish those two websites in this folder to the correct azure location. Does anybody know a good approach to achieve a succesfull constant delivery with 2 websites?

推荐答案

我们使用这个在Azure服务Managetment API期间TFS生成。我们采用了这种样本code - 的Windows Azure ServiceManagement样品 - 作为一个命令行工具来构建任务中运行

We use the Azure Service Managetment API for this during a TFS build. We adapted this sample code - Windows Azure ServiceManagement Sample - as a command line tool to run in a build task.

HostedServiceList hostedServices = new HostedServiceList();
Dictionary<string, IServiceManagement> servicesOperations = new Dictionary<string, IServiceManagement>();

ParseArguments(args);
ProcessCheckServerCertificate();

// upload the package created during the build to Azure BLOB
var packageUrl = UploadFileToBlob(package);
var services = new ListHostedServicesCommand();
services.Run();
hostedServices = services.HostedServices;
.
.
.
foreach (var hostedService in hostedServices)
{
    Console.WriteLine("updating: " + hostedService.ServiceName);
    // get the deployment unique name - required for upgrade
    AzureCommand.HostedServiceName = hostedService.ServiceName;
    AzureCommand.DeploymentName = null;
    var getDeployment = new GetDeploymentCommand();
    getDeployment.Run();
    AzureCommand.DeploymentName = getDeployment.Deployment.Name;

    // upgrade the existing deployment    
    var upgradeDeployment = new UpgradeDeploymentCommand();
    upgradeDeployment.Run();
    servicesOperations.Add(upgradeDeployment.TrackingId, upgradeDeployment.ServiceManagement);
}
.
.
.
// check status of all operations submitted
foreach (var servicesOperation in servicesOperations)
{
    // check status of operations
    AzureCommand.WaitForAsyncOperation(servicesOperation.Value, servicesOperation.Key);
}

这里的UploadFileToBlob code ...

Here's the UploadFileToBlob code...

private string UploadFileToBlob(string file)
{
    // Retrieve storage account from connection string
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

    // Create the blob client
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

    // Retrieve reference to a previously created container
    CloudBlobContainer container = blobClient.GetContainerReference("mydeployments");

    // Retrieve reference to a blob
    var date = DateTime.UtcNow.ToString("yyyyMMdd-hhmmss-");
    var fileinfo = new FileInfo(file);
    if (fileinfo.Exists)
    {
        var fileToUpload = new FileInfo(file).Name;
        var filename = date + fileToUpload;
        try
        {
            CloudBlob blob = container.GetBlobReference(filename);

            // Create or overwrite the blob with contents from a local file
            using (var fileStream = System.IO.File.OpenRead(file))
            {
                blob.UploadFromStream(fileStream);
            }

            return blob.Uri.AbsoluteUri;
        }
        catch (Exception ex)
        {
            LogError("Error uploading file to blog: ", ex.Message);
            return "";
        }
    }

    LogError("Error - specified file does not exist: ", file);
    return "";
}

和在云服务的.proj文件中添加构建任务,指出,YourCommandLineTool.exe

And add the build task in the .proj file for the cloud service, pointed to "YourCommandLineTool.exe":

  <Import Project="$(CloudExtensionsDir)Microsoft.WindowsAzure.targets" />
  <Target Name="AzureDeploy" AfterTargets="CorePublish" DependsOnTargets="CorePublish" Condition="$(DeployToAzure) == 'true'">
    <Exec WorkingDirectory="$(MSBuildProjectDirectory)" Command="C:\WindowsAzure\Deploy\YourCommandLineTool.exe /log:$(MSBuildProjectDirectory)\AzureDeploy.log /package:$(MSBuildProjectDirectory)\$(PublishDir)$(AssemblyName).cspkg /config:$(MSBuildProjectDirectory)\$(PublishDir)ServiceConfiguration.$(Configuration).cscfg" />
  </Target>

这篇关于持续部署和放大器;交货的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆