Answered by:
How to deploy to App Service with MSDeploy in command line?

Question
-
I have an ASP.NET web app in App Service and I can publish to the "dev" slot using Visual Studio just fine, but I need to do that with our Jenkins CI/CD environment so I need a way to use a batch file to publish it with MSDeploy. Here's what I'm doing and the error message I receive:
"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
-source:package='myproject.zip'
-dest:
auto,
computerName="https://myproject-dev-slot.scm.azurewebsites.net",
userName="$myproject__dev",
password="***",
includeAcls="False"
-verb:sync -disableLink:AppPoolExtension
-disableLink:ContentExtension
-disableLink:CertificateExtension
-setParamFile:"myproject.SetParameters.xml"
Info: Using ID 'GUID' for connections to the remote server.
Error Code: ERROR_USER_NOT_ADMIN
More Information: Connected to 'myproject-dev.scm.azurewebsites.net' using the Web Deployment Agent Service,
but could not authorize.
Make sure you are an administrator on 'myproject-dev.scm.azurewebsites.net'.
Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_NOT_ADMIN.
Error: The remote server returned an error: (401) Unauthorized.
Error count: 1.
The error doesn't make sense because the Visual Studio and my batch script both use the same username and password. It works in Visual Studio but not the script.
The deployment package was build using the following commands.
msbuild.exe myproject.csproj /t:package /p:Configuration=Release
What could be the problem?
UPDATE:
Finally realized I was missing authType="Basic".
- Edited by Ray Cheng Tuesday, March 27, 2018 11:23 PM
Tuesday, March 20, 2018 12:02 AM
Answers
-
I see repeated initial auth challenges (401 response) between UTC 2018-03-26 15:12:22 and 2018-03-26 16:10:28. However, for none of them is there a second request with the credentials for the site.
If you were passing in the wrong credentials, I would expect to see a second request with a response of 403 Forbidden. However, I don't see those. So, it looks like the credentials aren't even being passed to MSDeploy.exe.
I would suggest executing MSDeploy.exe from the command line on your box, passing in the correct credentials for the slot, and verifying it works there.
- Marked as answer by Ray Cheng Wednesday, March 28, 2018 10:36 PM
Tuesday, March 27, 2018 6:12 PM
All replies
-
Make sure that you have enter the existing publishing username & password.
If you have a slot "Staging" and a site "foo", the publishing user name is $foo__Staging.
Also, the staging site has a different password from the main site. So, you should get the publish settings "Get publish profile" in the portal for the slot and use those credentials.
------------------------------------------------------------------------------------------------------------------
Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.
- Proposed as answer by Sheethal J S Friday, March 23, 2018 4:36 AM
Friday, March 23, 2018 4:36 AM -
Thank you for the reply Sheethal. I have confirmed the user name is correct and password is from the specific slot but still getting that error.
I have also tried to reset and re-download the publish profile and use new credentials but still the same error.
- Edited by Ray Cheng Friday, March 23, 2018 10:43 PM
Friday, March 23, 2018 9:57 PM -
To confirm if user and password are correct, try accessing FTP (ftp endpoint will be in publish profile) and see if that works. If it works and you still have issues with MSDeploy, share us the sitename (https://github.com/projectkudu/kudu/wiki/Reporting-your-site-name-without-posting-it-publicly) and time frame of operation in UTC. we can look at the log and see what went wrong.
Suwatch
Saturday, March 24, 2018 4:44 PM -
Ah....the computerName param is incomplete. The URL needs the '/msdeploy.axd?site=<sitename>' suffix. The command should be:
"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package='myproject.zip',includeAcls="False" -dest:auto, computerName="https://myproject-dev-slot.scm.azurewebsites.net:443/msdeploy.axd?site=myproject__dev", userName="$myproject__dev", password="<slot_password>", includeAcls="False" -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"myproject.SetParameters.xml"
I'm not sure why the publishUrl in the *.PublishSettings file doesn't include this (or the 'https://' prefix).
Also, I'm assuming this is a Windows site, and not a Linux site. If it's a Linux site, then it's a bit trickier to get the publishing URL for MSDeploy.- Proposed as answer by David Ebbo Sunday, March 25, 2018 8:43 PM
Saturday, March 24, 2018 6:58 PM -
Suwat Ch,
I can connect with FTP fine. So here I created a dummy site: dummy741852
Then I published twice during UTC March 26th 2018 4:10pm - 4:11pm.
The site name starts with "w".
Please see if you can find anything in the log.
- Edited by Ray Cheng Monday, March 26, 2018 5:20 PM
Monday, March 26, 2018 4:15 PM -
Eric Stenson,
That makes sense, but I still get the same error after adding that to the URL. I have created a dummy site for Suwat Ch to look into the log.
- Edited by Ray Cheng Monday, March 26, 2018 5:19 PM
Monday, March 26, 2018 4:17 PM -
I see repeated initial auth challenges (401 response) between UTC 2018-03-26 15:12:22 and 2018-03-26 16:10:28. However, for none of them is there a second request with the credentials for the site.
If you were passing in the wrong credentials, I would expect to see a second request with a response of 403 Forbidden. However, I don't see those. So, it looks like the credentials aren't even being passed to MSDeploy.exe.
I would suggest executing MSDeploy.exe from the command line on your box, passing in the correct credentials for the slot, and verifying it works there.
- Marked as answer by Ray Cheng Wednesday, March 28, 2018 10:36 PM
Tuesday, March 27, 2018 6:12 PM -
EricSten,
I have been using a batch file to execute the commands already, but I got the same error when I paste the commands into a command line window. The cred I use is from the downloaded publish file of dev slot.
I then tried to import the publish file to VS and publish from there and it worked.
I created a test project in TFVC with the batch script to reproduce the error. Is there a way for me to add you to the team project?
Tuesday, March 27, 2018 9:10 PM -
If you are using TFS or VSTS, you can Add users to a team project or specific team.
Check the below link for more information and let us know if this helps.
https://docs.microsoft.com/en-us/vsts/security/add-users-team-project?view=vsts
------------------------------------------------------------------------------------------------------------------
Do click on "Mark as Answer" on the post that helps you, this can be beneficial to other community members.
Wednesday, March 28, 2018 7:41 AM