azure-pipelines-tasks: App Service Deployment to Slot: 401 Unauthorized

Required Information

Question, Bug, or Feature?
Type: Question

Enter Task Name: Azure App Service Deploy

Environment

  • Server - Azure Pipelines
  • Agent - Hosted VS2017

Issue Description

When trying to deploy an App Service to a slot, we are getting a ERROR_USER_UNAUTHORIZED error. In our DevOps pipeline the only task which is executed is Azure App Service Deploy. When deploying to the production slot everthing works.

Task logs

2019-04-23T08:37:04.7233325Z ##[section]Starting: Azure App Service Deploy: MYSERVICENAME
2019-04-23T08:37:04.7350800Z ==============================================================================
2019-04-23T08:37:04.7350934Z Task         : Azure App Service Deploy
2019-04-23T08:37:04.7351060Z Description  : Update Azure App Services on Windows, Web App on Linux with built-in images or Docker containers, ASP.NET, .NET Core, PHP, Python or Node.js based Web applications, Function Apps on Windows or Linux with Docker Containers, Mobile Apps, API applications, Web Jobs using Web Deploy / Kudu REST APIs
2019-04-23T08:37:04.7351172Z Version      : 4.3.22
2019-04-23T08:37:04.7351250Z Author       : Microsoft Corporation
2019-04-23T08:37:04.7351325Z Help         : [More information](https://aka.ms/azurermwebdeployreadme)
2019-04-23T08:37:04.7351426Z ==============================================================================
2019-04-23T08:37:05.4828038Z Got service connection details for Azure App Service:'MYSERVICENAME'
2019-04-23T08:37:06.0464757Z Updating App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"0"}
2019-04-23T08:37:06.6191045Z Updated App Service Application settings and Kudu Application settings.
2019-04-23T08:37:07.3334865Z [command]"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package='d:\a\r1\a\_MYSERVICENAME\drop\WebApp.zip' -dest:auto,ComputerName='https://*.publish.azurewebsites.windows.net:443/msdeploy.axd?site=MYSERVICENAME',UserName='$MYSERVICENAME__staging',Password='***',AuthType='Basic' -setParam:name='IIS Web Application Name',value='MYSERVICENAME' -enableRule:AppOffline -skip:Directory=App_Data -retryAttempts:6 -retryInterval:10000 -enableRule:DoNotDeleteRule -userAgent:VSTS_xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx_Release__146_184_1
2019-04-23T08:37:15.9886411Z Info: Using ID 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx' for connections to the remote server.
2019-04-23T08:37:19.3426774Z [command]"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package='d:\a\r1\a\_MYSERVICENAME\drop\WebApp.zip' -dest:auto,ComputerName='https://*publish.azurewebsites.windows.net:443/msdeploy.axd?site=MYSERVICENAME',UserName='$MYSERVICENAME__staging',Password='***',AuthType='Basic' -setParam:name='IIS Web Application Name',value='MYSERVICENAME' -enableRule:AppOffline -skip:Directory=App_Data -retryAttempts:6 -retryInterval:10000 -enableRule:DoNotDeleteRule -userAgent:VSTS_xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx_Release__146_184_1
2019-04-23T08:37:19.9360569Z Info: Using ID 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx' for connections to the remote server.
2019-04-23T08:37:21.3028922Z [command]"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package='d:\a\r1\a\_MYSERVICENAME\drop\WebApp.zip' -dest:auto,ComputerName='https://*.publish.azurewebsites.windows.net:443/msdeploy.axd?site=MYSERVICENAME',UserName='$MYSERVICENAME__staging',Password='***',AuthType='Basic' -setParam:name='IIS Web Application Name',value='MYSERVICENAME' -enableRule:AppOffline -skip:Directory=App_Data -retryAttempts:6 -retryInterval:10000 -enableRule:DoNotDeleteRule -userAgent:VSTS_xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx_Release__146_184_1
2019-04-23T08:37:21.9054780Z Info: Using ID 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx' for connections to the remote server.
2019-04-23T08:37:22.5946041Z ##[error]Error: Error Code: ERROR_USER_UNAUTHORIZED
More Information: Connected to the remote computer ("*.publish.azurewebsites.windows.net") 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.
Error count: 1.

2019-04-23T08:37:24.5622625Z Successfully added release annotation to the Application Insight : MYSERVICE
2019-04-23T08:37:24.9989564Z Successfully updated deployment History at https://MYSERVICENAME-staging.scm.azurewebsites.net/api/deployments/1461556008644560
2019-04-23T08:37:25.0008895Z App Service Application URL: http://MYSERVICENAME-staging.azurewebsites.net
2019-04-23T08:37:25.0104286Z ##[section]Finishing: Azure App Service Deploy: MYSERVICENAME

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 19 (1 by maintainers)

Most upvoted comments

I’m also getting 401 Unauthorized errors for App Service Deployments. Started suddenly after months of successful deployments with no change to my workflow.

I was able to mitigate by enabling Basic Authentication under Configuration -> General Settings: image

I’m also getting 401 Unauthorized errors for App Service Deployments. Started suddenly after months of successful deployments with no change to my workflow.

Turned out to be a security policy that disables basic auth for mine. Switching to a service principal with contributor access to our app service fixed the issue. Had to remove the publish-profile config from the workflow and add an az login step.

@AaronCrawfis , I got this error again today, here is details:

I observe that when even I set ‘All allowed’ in dropdownlist FTP State and turn Basic Auth = ‘On’, click Save settings and restart app service => it automatically returns to ‘Off’.

image

and I find out debug logs:

image

Any ideas for this?

@Valay14 This has to be set at the service app level. Go to the App Service in your Azure Portal. On the left hand navigation, look for Settings section and click on Configuration. There on the landing screen you can add AppSettings variables.

@Schirmi136 , Can you set an application setting WEBSITE_WEBDEPLOY_USE_SCM to value true in Azure Portal and retry the deployment after 1 min. Also, we recommend choosing Zip Deploy or Website Run From Package as deployment method. Please follow the steps here for the same. 😃