我一直在研究使用MSDEPLOY的TFS2010新构建和部署功能。到目前为止,一切进展顺利(尽管很难找到有关特定场景的信息)。

我可以修改构建定义以指定2个或更多服务器要部署吗?我需要做的是部署到多个服务器(因为我在使用NLB的测试环境中有两个)。

我现在拥有的是一个构建定义,该定义可以构建,运行测试,然后部署到我的一个测试服务器之一(在其上有MSDeployAgentService运行)。它运行良好,每个Web项目都按照其项目文件中的配置部署。我使用的msbuild论点是:

* /p:DeployOnBuild=True
* /p:DeployTarget=MsDeployPublish
* /p:MSDeployServiceURL=http://oawww.testserver1.com.au/MsDeployAgentService
* /p:CreatePackageOnPublish=True
* /p:MsDeployPublishMethod=RemoteAgent
* /p:AllowUntrustedCertificated=True
* /p:UserName=myusername
* /p:Password=mypassword 

NB:我不使用 /p:deployiisapppath =“ xyz”,因为它没有部署我的所有项目并覆盖我的项目配置。

我可以添加另一个构建参数以使其调用多个msdeployserviceurl吗?像second /p这样的东西:指定另一个服务器的MSDEPLOYSERVICEURL参数?

还是我必须寻找其他解决方案,例如编辑WF?

我在2个月前发布了一个几乎完全相同的问题: TFS 2010-构建后部署到多个服务器 ,因此看起来我并不是唯一一个试图解决这个问题的人。

我还在IIS.NET论坛上发布了讨论MSDeploy的论坛: http://forums.iis.net/t/1170741.aspx 。它有很多视图,但又是没有答案。

有帮助吗?

解决方案

您无需两次构建项目即可部署到两个服务器。构建过程将构建一组部署文件。然后,您可以使用InvokeProcess部署到多个服务器。

首先创建一个名为projectName的变量。然后将分配活动添加到“编译项目”序列中。这位于“尝试编译项目”序列中。这是分配的属性:

To: ProjectName
Value: System.IO.Path.GetFileNameWithoutExtension(localProject)

以下是我们的InvokeProcess活动的属性,该活动部署到测试服务器:

Arguments: "/y /M:<server> /u:<domain>\<user> /p:<password>"
FileName: String.Format("{0}\{1}.deploy.cmd", BuildDetail.DropLocation, ProjectName)

You will need to change <server>, <domain>, <user>, and <password> to the values that reflect your environment.

如果您需要手动部署到服务器,则可以从构建文件夹中运行下面的命令:

deploy.cmd /y /M:<server> /u:<domain>\<user> /p:<password>

其他提示

我找不到想要的解决方案,但这是我最终想到的。

我想将解决方案保持简单,可配置在TFS参数中,同时与已经提供的 MSBuildArguments 经常促进的方法。因此,我创建了一个新的构建模板,并添加了一个新的TFS工作流参数称为 MSBuildArguments2 在工作流的“参数”选项卡中。

alt text

我浏览了buildTemplate的工作流程,以了解 MSBuildArguments (发生了两次)。

使用的两个任务 MSBuildArguments 被称为 Run MSBuild for Project. 。直接在此任务下方,我添加了一个具有条件的新“ If”块:

Not String.IsNullOrEmpty(MSBuildArguments2)

然后,我复制了“为项目的运行MSBUILD”任务,并将其粘贴到新的IF“然后”块中,并相应地更新其标题。您还需要更新新任务的conmmandlinearguments属性以使用您的新参数。

CommandLineArguments = String.Format("/p:SkipInvalidConfigurations=true {0}", MSBuildArguments2)

经过这些修改后,工作流程看起来像这样:

alt text

保存并检查新的工作流程。更新您的构建定义以使用此新工作流程,然后在“构建定义”的过程选项卡中,您会找到一个名为MISC的新部分,并准备使用新参数。因为我只是简单地使用这个新论点进行部署,所以我复制了我使用的完全相同的论点 MSBuild Arguments 并将MSDEPLOYSERVICEURL更新为我的第二个部署服务器。

alt text

就是这样。我想一种更优雅的方法是将MSBuildArguments转换为一系列字符串,然后在工作流程过程中循环通过它们。但这适合我们的2个服务器要求。

希望这可以帮助!

我对此的解决方案是一个新目标,可在包装后运行。每个需要生产包装的项目都包含此目标文件,我选择在外部设置的“躲避”属性上制作包含条件。此外,每个项目都定义了deploymentservergroup属性,以使目标服务器得到正确过滤,具体取决于它是什么样的项目。

如您所见,我只是简单地使用服务器列表执行命令文件,非常简单。

<!-- 
This targets file allows a project to deploy its package  

As it is used by all project typesconditionally included from the project file 

-->

<UsingTask TaskName="Microsoft.TeamFoundation.Build.Tasks.BuildStep" AssemblyFile="$(TeamBuildRefPath)\Microsoft.TeamFoundation.Build.ProcessComponents.dll" />

<!-- Each Server needs the Group metadatum, either Webservers, Appservers, or Batch. -->
<Choose>
    <When Condition="'$(Configuration)' == 'DEV'">
        <ItemGroup>
            <Servers Include="DevWebServer">
                <Group>Webservers</Group>
            </Servers>
            <Servers Include="DevAppServer">
                <Group>Appservers</Group>
            </Servers>
        </ItemGroup>
    </When>
    <When Condition="'$(Configuration)' == 'QA'">
        <ItemGroup>
            <Servers Include="QAWebServer1">
                <Group>Webservers</Group>
            </Servers>
            <Servers Include="QAWebServer2">
                <Group>Webservers</Group>
            </Servers>
            <Servers Include="QAAppServer1">
                <Group>Appservers</Group>
            </Servers>
            <Servers Include="QAAppServer2">
                <Group>Appservers</Group>
            </Servers>
        </ItemGroup>
    </When>
</Choose>

<!-- DoDeploy can be set in the build defintion -->
<Target Name="StartDeployment" AfterTargets="Package">

    <PropertyGroup>
        <!-- The _PublishedWebsites area -->
        <PackageLocation>$(WebProjectOutputDir)_Package</PackageLocation>

        <!-- Override for local testing -->
        <PackageLocation Condition="$(WebProjectOutputDirInsideProject)">$(IntermediateOutputPath)Package\</PackageLocation>

    </PropertyGroup>

    <Message Text="Tier servers are @(Servers)" />

    <!-- A filtered list of the servers.  DeploymentServerGroup is defined in each project that does deployment -->
    <ItemGroup>
        <DestinationServers Include="@(Servers)" Condition="'%(Servers.Group)' == '$(DeploymentServerGroup)'" />
    </ItemGroup>

    <Message Text="Dest servers are @(DestinationServers)" />

</Target>

<!-- Only perform the deployment if any servers fit the filters -->
<Target Name="PerformDeployment" AfterTargets="StartDeployment" Condition="'@(DestinationServers)' != ''">

    <Message Text="Deploying $(AssemblyName) to @(DestinationServers)" />

    <!-- Fancy build steps so that they better appear in the build explorer -->
    <BuildStep
                    TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                    BuildUri="$(BuildUri)"
                    Message="Deploying $(AssemblyName) to @(DestinationServers)...">
        <Output TaskParameter="Id" PropertyName="StepId" />
    </BuildStep>

    <!-- The deployment command will be run for each item in the DestinationServers collection.  -->
    <Exec Command="$(AssemblyName).deploy.cmd /Y /M:%(DestinationServers.Identity)" WorkingDirectory="$(PackageLocation)" />

    <BuildStep
                    TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
                    BuildUri="$(BuildUri)"
                    Id="$(StepId)"
                    Status="Succeeded"
                    Message="Deployed $(AssemblyName) to @(DestinationServers)"/>
    <OnError ExecuteTargets="MarkDeployStepAsFailed" />
</Target>

<Target Name="MarkDeployStepAsFailed">
    <BuildStep
            TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
            BuildUri="$(BuildUri)"
            Id="$(StepId)"
            Status="Failed" />
</Target>

我是其他类似帖子的作者。我还没有找到解决方案。我相信它将修改工作流程以添加后处理MSBUILD -SYNC任务。这似乎是最优雅的,但仍然希望找到一些侵入性的东西。

我不确定这是否可以帮助您使用TFS 2010,但是我有一篇有关TFS 2012的博客文章: 从TFS 2012到启用NLB的多个Web项目部署.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top