2013-04-26 102 views
1

我們有一個包含+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

回答

3

我們在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>