DotNet98
DotNet98

Reputation: 747

Teamcity and msdeploy using powershell

I developed a powershell script that accepts a buncha parameters, creates an MSDeploy string, and executes it. I've tested this powershell command:

  1. It works on my local box (installs the web app from my local box to a remote IIS server)
  2. It works on the TeamCity box (installs the web app from team city's folder structure to remote iis server)

problem:

It doesn't work when I run the command from teamcity's browser version.

The error is: ERROR_USER_NOT_ADMIN

Please note, my Teamcity Build Agent is a local admin on both my teamcity server and IIS Remote server

Powreshell Source Code:

$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 call to the above script file:

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^^^ ^^^Password^^^ false

Upvotes: 0

Views: 1013

Answers (1)

John Hoerr
John Hoerr

Reputation: 8025

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

Upvotes: 2

Related Questions