How to pass the sitename in ProjectName.deploy.cmd - deployment

I am trying to run the ProjectName.deply.cmd that is generated by MSBuild when the paramter /p:DeployOnBuild=True is passed. One of the argument "ComputerName" is to be passed as https://WebServer01:8172/MSDeploy.axd?SiteName=MySiteName. My command line would be
ProjectName.deploy.cmd /Y /M:https://WebServer01:8172/MSDeploy.axd?Site=MySiteName
-AllowUntrusted /U:DeployUserName /P:Password /A:Basic
It returns
Error: Unrecognized argument 'MySiteName'. All arguments must begin with "-".
the actual command that is executed is
"C:\Program Files\IIS\Microsoft Web Deploy V3\\msdeploy.exe"
-source:package='Y:\ProjectName.zip'
-dest:auto,computerName='https://WebServer01:8172/MSDeploy.axd?Site',userName='DeployUserName',password='Password',authtype='Basic',includeAcls='False'
-verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension
-disableLink:CertificateExtension
-setParamFile:"Y:\ProjectName.SetParameters.xml"
MySiteName
-AllowUntrusted
Notice that the argument to /M https://WebServer01:8172/MSDeploy.axd?Site=MySiteName is split into two arguments and thus creating computerName='https://WebServer01:8172/MSDeploy.axd?Site' and and extra argument MySiteName.
I have gone through Running a deployment package with quoted parameters fails in Visual Studio 2010 Service Pack 1 but that takes care of only ArgMsDeployAdditionalFlags and not the arguments e.g. /M:ComputerName.
When the SiteName is not passed, I can do the deployment fine with an user that had admin rights on the server but when a standard IIS user DeployUserName is used I get 401
ProjectName.deploy.cmd /Y /M:https://WebServer01:8172/MSDeploy.axd
-AllowUntrusted /U:DeployUserName /P:Password /A:Basic
The server returns 401
Error Code: ERROR_USER_UNAUTHORIZED
More Information: Connected to the remote computer ("WebServer01") using the Web
Management Service, but could not authorize. Make sure that you are using the
correct user name and password, that the site you are connecting to exists, and
that the credentials represent a user who has permissions to access the site.
Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.
Error: The remote server returned an error: (401) Unauthorized.
The permissions for that user are fine as the publish from VS2012 with MSDeploy profile using that user works just fine. I can also build msdeploy.exe command and that also runs fine. I have to use the ProjectName.deploy.cmd as it is being produced as part of Team Build from TFS2010.

Have you tried quoting the argument?
ProjectName.deploy.cmd /Y "/M:https://WebServer01:8172/MSDeploy.axd?Site=MySiteName"
-AllowUntrusted /U:DeployUserName /P:Password /A:Basic

Thought I'd add to the answer for anyone else like me that stumbles upon this trying to figure out why this doesn't work, and who'd like the equivalent msdeploy command.
As mentioned in the comments quoting the argument won't work due to a bug in how the arguments are parsed, from MS docs:
At the time of writing, due to a bug in the Web Publishing Pipeline
(WPP), you can't run the .deploy.cmd file using an endpoint address
that includes a query string. In this scenario, you need to deploy
your web package by using MSDeploy.exe directly.
Source: https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/web-deployment-in-the-enterprise/deploying-web-packages
So, instead, you should use MSDeploy directly. Equivalent to the deploy.cmd arguments in the question:
MSDeploy.exe -source:package='<fullPathToDeployable>\<projectName>.zip'
-dest:auto,computerName="https://<ipOrDnsName>:8172/MSDeploy.axd",userName="<userName>",password="<pwd>",authtype="Basic",includeAcls="False"
-verb:sync
-disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-setParamFile:"<fullPathToDeployable>\<projectName>.SetParameters.xml"
-setParam:name="IIS Web Application Name",value="<siteName>"
-AllowUntrusted
(replace angle-bracketed words)

Related

Jenkins parameter Release versus Staging

I created a freestyle job in Jenkins that I just set up (latest version).
I added parameters to it. One of those is a Options selection for ReleaseType with the options of Staging and Release.
One of the build steps is executing a remote command on the server when the site is uploaded to. It uses the Execute Windows Batch Command build step.
Here is the command line (with things made generic):
sexec myuser#mysite.com -pw=mypassword -cmd="PowerShell -Command ""C:\batch\bvCopyFast.ps1 C:\inetpub\mysite${ReleaseType}\siteLoad C:\inetpub\mysite${ReleaseType}\site""
Basically I am executing a powershell command that uses Robocopy to copy the files from the upload folder to the actual release folder for the site.
As you can see I need to have the ${ReleaseType} replaced with the actual value. The problem is that when this gets executed it isn't doing the substitution. I just uses that literal value in the command and that doesn't work.
If you use the -Command parameter it implies you are going to write raw PowerShell code in between the quotation marks that follow (allow you can call a script as you have).
PowerShell -Command "Get-Date; pause;"
To call a PowerShell script file you should use:
PowerShell -File "Your-Script.ps1 -Parameter1 Argument1 -Parameter2 Argument2"
https://learn.microsoft.com/en-us/powershell/scripting/components/console/powershell.exe-command-line-help?view=powershell-6
I would write a PowerShell script that accepted your root path and the releaseType as arguments and execute that.
Param($rootPath,$releaseType)
{
robocopy "$($rootPath)\$($releaseType)\siteLoad" "$($rootPath)\$($releaseType)\site"
}
I have never used Jenkins so I hope this works as I expect it to!
sexec myuser#mysite.com -pw=mypassword -cmd=""PowerShell -File 'C:\batch\newScript.ps1' -RootPath 'c:\inetpub\mysite' -ReleaseType {ReleaseType}""

VSTS release, CMD webdeploy with variables inside Powershell quotation syntax

Apologies in advance if this is dumb and obvious. I have the following lines in a Powershell script executing as a release task in VSTS:
Write-Output "Stopping IIS..."
CMD.exe /C "'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' -verb:sync -source:recycleApp -dest:recycleApp='MyApp/MyAppPool',recycleMode='StopAppPool',computername=$privateIp,userName=$serverLogin,password=$serverPassword"
It produces the following output:
2017-10-07T15:07:33.3282985Z Stopping IIS...
2017-10-07T15:07:34.5470804Z ##[error]The filename, directory name, or volume label syntax is incorrect
Per MS (https://technet.microsoft.com/en-us/library/cc956689.aspx) this means one of the following characters is wrong: \ \ / [ ] : | < > + ; = . ? "
I can only assume it's my quote syntax because that's the only character used on this line. I know it's not the contents of any of the variables, because they are used elsewhere in the script with no problem (and don't contain any of the characters in question).
Help?
After a lot of trial and error, I figured out the answer:
CMD.exe /C "`"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe`" -verb:sync -source:recycleApp -dest:recycleApp='MySite/MySiteAppPool',recycleMode='StopAppPool',computername=$privateIp,userName=$serverLogin,password=$serverPassword"
Just a note for posterity, this is specifically a syntax that will work when you are attempting to stop/start/recycle an app pool on a server on the network, from a Powershell script, as a release task in VSTS, using msdeploy.

How to run Powershell file (having extension .ps1) using jmeter?

I want to execute .ps1 file in jmeter. I have pass the parameter as in image,but in output facing errors.The filename, directory name, or volume label syntax is incorrect.
Though the filename, directory name are correct.
Here is your problem:
Remove that quotation mark and everything should start working as expected
In general, you are making things overcomplicated.
Why do you need these cmd /c? Why just don't call powershell directly?
Normally powershell is in Windows PATH, there is no need to provide full path to it
So configure your OS Process Sampler as:
Command: powershell
Parameter: D:\Software\apache=jmeter-3.0\apache-jmeter-3.0\bin\TIP.ps1
See How to Run External Commands and Programs Locally and Remotely from JMeter article for more information on invoking 3rd-party processes from your JMeter test.
I know this is an old thread but since the response was not correct for me I found the solution to be this:
Using the OS Process Sampler you need to add as command powershell.exe and as variables exactly the following:
-executionpolicy
bypass
-file
fullpathToYourScript.ps1
This worked perfectly fine for me.

MSBuild from Powershell

I'm trying to run a Sync from MSBuild (From Powershell) that also includes Pre Sync Commands.
I am unable to get the commands right. I've tried multiple ways, but the final way I'm up to is :
[string[]]$msdeployArgs = #(
"-verb:sync",
"-preSync:runCommand='$preSyncCommand',waitInterval=30000",
"-source:dirPath=$sourceFolder",
"-dest:computerName=$serverName,userName=$username,password=$password,authType=basic,dirPath=$serviceFolder",
"-postSync:runCommand=$postSyncCommand,waitInterval=30000"
)
& "C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" $msdeployArgs
I get the following error.
Error: Unrecognized argument
'"-preSync:runCommand='F:\Projects\Unleashed\Release_Scripts\WindowsServices\deployTopShelfServicePreCommands.cmd
Unleashed.Maintenance.JobScheduler
C:\MyCompany\Services\MyCompany.Maintenance.JobScheduler',waitInterval=30000"'.
All arguments must begin with "-".
Note that after the PreSyncCommand, is params that I want to pass to the CMD file (For it to know where to uninstall the existing service from etc.
I've ran that params via EchoArgs.exe, and the args are fine.
If it matters (It might), I'm running the powershell script from TeamCity.
I've found the issue. As it turns out, it isn't powershell with the issue, but MSDeploy. MSDeploy as far as I can see does not allow you to pass batch files with parameters. Removing the parameters works fine (But then you need to hardcode them in your batch file, or work out some other way of generating the bat files on the fly).

Running msdeploy.exe from within Powershell

I'm trying to run the following command from within Powershell:
msdeploy -verb:sync -source:archiveDir=c:\KitchenPC\Build -dest:appHostConfig="KitchenPC",computerName=https://192.168.0.3:8172/msdeploy.axd,authType=Basic,userName=someuser,password="secret" -allowUntrusted
The docs say to simply substitute the : after each parameter with an =. So I've tried this:
msdeploy -verb=sync -source=archiveDir=c:\KitchenPC\Build -dest=appHostConfig="KitchenPC",computerName=https://192.168.0.3:8172/msdeploy.axd,authType=Basic,userName=someuser,password="secret" -allowUntrusted
However, I get the error:
Error: Unrecognized argument
'computerName=https://192.168.0.3:8172/msdeploy.axd'. All arguments
must begin with "-". Error count: 1.
I've checked the docs on provider settings, however they have no mention of their equivelent Powershell syntax.
How do you call msdeploy from powershell when the parameters have spaces?
Think this is already answered, just modify it.
Ex. include "KitchenPC" and "secret" using variables, and put the -dest part inside quotation marks.
Working Example:
msdeploy '-verb=sync' '-source=archiveDir=c:\KitchenPC\Build -dest=appHostConfig="KitchenPC",computerName=https://192.168.0.3:8172/msdeploy.axd,authType=Basic,userName=someuser,password="secret"' -allowUntrusted
(Note single quotes around each command line argument)