持续部署和交付(Continuous deployment & delivery)

2019-09-01 04:51发布

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

编辑:

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

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

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

Answer 1:

我们用这个在Azure服务Managetment API一个TFS构建过程中。 我们适应这个示例代码- Windows Azure的ServiceManagement样品 -作为一个命令行工具来构建任务运行。

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>


文章来源: Continuous deployment & delivery