连续部署和交付

问题描述:

我们有一个包含+10个项目的解决方案,其中2个是网站。现在我需要设置一个链接到我们的TFS服务器的构建定义,构建解决方案并将这两个站点部署到正确的Azure网站。我尝试了几种不同的方法,但是交付似乎每次都失败。在TFS服务器上构建项目不成问题,但是当azure需要将正确的asp项目提供给正确的Azure网站时,它会失败......任何人都可以指出我如何创建这样的构建定义的正确方向,以及在哪里指定交付选项?连续部署和交付

编辑:

为了说明从我们构建的图像。

docl builddefinition

所以我们有2个网站,此文件夹中: enter image description here

我想在此文件夹中发布这些两个网站,以正确的蔚蓝位置。 有没有人知道一个很好的方法来实现与2个网站succesfull恒定交付?

+0

你可能想提供一些关于它如何失败的信息。 – Alistair 2013-04-26 11:29:19

+0

我认为这不重要,因为我确定有更好的方法来创建持续集成构建定义。我对这个概念很感兴趣,但其中一个错误是ERROR_APPPOOL_VERSION_MISMATCH。我不希望人们纠正我的不好的定义,我想要一些关于如何处理这样的问题的指示(不是我的错误,但是如何确保解决方案在TFS上调试,并且天蓝色部署在它应该在的位置)。 – Chris 2013-04-26 12:54:25

+0

与论坛网站不同,我们不使用“谢谢”或“任何帮助表示赞赏”,或在[so]上签名。请参阅“[应该'嗨','谢谢',标语和致敬从帖子中删除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be -removed-from-posts) – 2013-04-26 19:25:19

我们在TFS构建过程中使用Azure Service Managetment API。我们修改了这个示例代码 - Windows Azure ServiceManagement Sample - 作为在构建任务中运行的命令行工具。

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代码...

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”:

<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>