【问题标题】:Teamcity and msdeploy using powershellTeamcity 和 msdeploy 使用 powershell
【发布时间】:2014-03-31 19:40:33
【问题描述】:

我开发了一个 powershell 脚本,它接受一个 bundlea 参数、创建一个 MSDeploy 字符串并执行它。我已经测试了这个 powershell 命令:

  1. 它适用于我的本地盒子(从我的本地盒子安装 Web 应用程序到 远程 IIS 服务器)
  2. 它适用于 TeamCity 盒子(安装 web 应用程序从团队城市的文件夹结构到远程 iis 服务器)

问题:

当我从 teamcity 的浏览器版本运行命令时它不起作用。

错误是:ERROR_USER_NOT_ADMIN

请注意,我的 Teamcity Build Agent 是我的 teamcity 服务器和 IIS 远程服务器上的本地管理员

Powreshell 源代码:

$msDeploy = 'C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe'
$sourcePackage = $args[0]
$paramFile = $args[1]
$iisAppPath = $args[2]
$servername = $args[3]
$usreName = $args[4]
$password = $args[5]
$includeAcls = $args[6]

function UpdateParamFile($paramXMLFile, $applicationPath)
{
    $doc = New-Object System.Xml.XmlDocument
    $doc.Load($paramXMLFile)

    #IIS Application Path (this is where the code will be deployed - it has to exist in target IIS):
    $appPath = $doc.SelectSingleNode("//parameters//setParameter[@name = 'IIS Web Application Name']")
    $appPath.value = $applicationPath

    #Connection Strings:

    #KDB Connection string:

    #Save
    $doc.Save($paramXMLFile)

    #[xml] $xmlPars = Get-Content $paramXMLFile
    #$xmlPars.parameters.setParameter | Where-Object { $_.name -eq 'IIS Web Application Name' } | select value
}

UpdateParamFile $paramFile $iisAppPath
$arguments = "-source:package=$sourcePackage", "-dest:auto,computerName=`"$servername`",userName=`"$usreName`",password=`"$password`",includeAcls=`"$includeAcls`"", "-setParamFile:$paramFile", '-verb:sync', '-disableLink:AppPoolExtension', '-disableLink:CertificateExtension', '-disableLink:ContentExtension'
&$msDeploy $arguments

Teamcity 调用上述脚本文件:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -文件 C:\TeamCity\buildAgent\work\253e6183c0596123\Debug\PMRSWebsite\DeployWeb.ps1 Debug\PMRSWebsite\Web。 csproj.zip "Debug\PMRSWebsite\Web.csproj.SetParameters.xml" ^^^IIS_APP_NAME^^^ ^^^ServerName^^^ ^^^userName^^^ ^^^Password^^^ false

【问题讨论】:

    标签: powershell msbuild teamcity msdeploy


    【解决方案1】:
    ERROR_USER_NOT_ADMIN
    
    Diagnosis - This happens if you try to connect to the Remote Agent Service but 
      have not provided appropriate administrator credentials.
    
    Resolution - The Remote Agent Service accepts either built-in Administrator or 
      Domain Administrator credentials. If you have a non-domain setup and want to 
      use account other that built-in administrator, please do following:
    
      1. Create a separate user group MSDepSvcUsers on remote computer.
      2. Create an local account A on both local & remote computer.
      3. Add A to MSDepSvcUsers on remote computer.
      4. Use account A to publish, this will allow you to publish without needing to 
         use built-in admin account.
    

    via

    【讨论】:

    • 不,这不会/不是解决所述问题的方法。我使用的帐户实际上是两个盒子上的本地管理员;正如我之前提到的,我能够运行 msdeploy 没有问题;但是,从 Teamcity 执行完全相同的 msdeploy 代码时会出现 ERROR_USER_NOT_ADMIN 错误。 Teamcity 的构建代理也在两个机器上的本地管理员帐户和域管理员帐户下运行。为了清楚起见,我从命令行中运行的 TeamCity 框中运行 msdeploy 代码。出现错误的是 Teamcity 的浏览器版本。我认为管理错误是一个红鲱鱼
    • 您尝试过这里介绍的解决方案吗?
    • 是的,我做到了。关于“帐户”,我们是在谈论在 msdeploy 的 -dest 参数中指定的帐户,还是在谈论正在调用 msdeploy 的帐户(即,teamcity 构建代理服务帐户)?谢谢你和我一起跟进这个问题:)
    • 开始工作了!问题与我从 TeamCity 生成 msdeploy 脚本的方式有关。在 teamcity 中,我将脚本参数化为接受用户名、密码等,并且在传入的值周围加上单引号!!!因此它无法验证我的用户。我不知道我是否高兴,失望,...无论如何,对于您的帮助,绝对是我的加分!干杯
    猜你喜欢
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 2012-12-10
    • 2010-10-10
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    相关资源
    最近更新 更多