使用PowerShell的Teamcity和msdeploy

时间:2014-02-28 01:30:04

标签: powershell msbuild teamcity msdeploy

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

  1. 它适用于我的本地方框(从我的本地方框安装网络应用程序到 远程IIS服务器)
  2. 适用于TeamCity框(安装网页) 应用程序从团队城市的文件夹结构到远程iis服务器)
  3. 问题:

    当我从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 -File 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 ^^^ ^^^密码^^^ false

1 个答案:

答案 0 :(得分:2)

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