Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBUILD publish ERROR_USER_UNAUTHORIZED

Summary

I'm using a 9.2.0 Gitlab's CI multirunner on a Windows Server 2016. On a step where I publish ASP.NET project through MSBUILD I've got an authentication error ERROR_USER_UNAUTHORIZED from IIS. But when I use a CMD window on a build machine there I run the same command for publish - everything is published. Doesn't matter if I used a SYSTEM or an ADMINISTRATOR account.

Steps to reproduce

  1. Setup IIS publish.
  2. Setup Gitlab's build agent.
  3. Create the Gitlab's YAML build script (see below).
  4. Run the build.

Actual behavior

On a publish step I've got the ERROR_USER_UNAUTHORIZED error.

Expected behavior

On a publish step I've got my ASP.NET published to a server.

Relevant logs and/or screenshots

  C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(4292,5): msdeploy error ERROR_USER_UNAUTHORIZED: Не удалось выполнить задачу Web Deploy. (Выполнено подключение к удаленному компьютеру ("192.168.1.66") с использованием службы веб-управления, но не удалось авторизовать. Убедитесь, что вы используете правильные имя пользователя и пароль, что существует сайт, к которому выполняется подключение, и что учетные данные представляют пользователя, у которого есть разрешения на доступ к сайту.  Дополнительные сведения: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.) [C:\Gitlab_Build_Agents\1\builds\2378ccf8\0\rushydro\aisa\Sources\Mvc\Mvc.csproj]

Environment description

I'm using a shared Runner (gitlab-ci-multi-runner-windows-386, version 9.2.0) on a Windows 2016. MSBUILD is a part of a Microsoft Visual Studio 2017.

YAML script

variables:
  solution: Sources\Faso.sln
  msbuild: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
  nunit: C:\NUnit\NUnit.Framework-3.7.0\bin\net-4.5\nunitlite-runner.exe
  nuget: C:\NuGet\nuget.exe

before_script:
  - echo Setting encoding...
  - echo %solution%
  - echo Restoring NuGet packages...
  - '"%nuget%" restore "%solution%"'

stages:
  - build-test
  - deploy-5023

build-test:
  stage: build-test
  script:  
  - chcp 65001
  - echo Building...
  - '"%msbuild%" "%solution%" /t:Build /p:Configuration=Release /p:TargetFramework=v4.5.2'
  - echo Testing...
  - dir /s /b *.Tests.dll | findstr /r Tests\\*\\bin\\ > testcontainers.txt
  - 'for /f %%f in (testcontainers.txt) do "%nunit%" "%%f"'
  except:
  - tags

deploy-5023:
  stage: deploy-5023
  script:
  - chcp 65001
  - echo Deploying...
  - '"%msbuild%" "%solution%" /p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MsDeployServiceUrl=https://192.168.1.66:8172/msdeploy.axd /p:username=user /p:password=password /p:Configuration=Release /p:TargetFramework=v4.5.2 /p:AllowUntrustedCertificate=True /p:DeployIisAppPath=Faso /p:MSDeployPublishMethod=WMSVC /p:SkipExtraFilesOnServer=True /p:ExcludeFilesFromDeployment="Web.config;ConnectionStrings.config;system.config"'
  when: manual
  except:
  - tags
  artifacts:
    expire_in: 1 week
    paths:
    - Sources\Mvc\App_Data\
    - Sources\Mvc\bin\
    - Sources\Mvc\Content\
    - Sources\Mvc\favicon.ico
    - Sources\Mvc\Global.asax
    - Sources\Mvc\Web.config
like image 833
Mark Twain Avatar asked Jun 16 '17 13:06

Mark Twain


1 Answers

Solved by changing the arguments' order and format for MSBUILD.

- '"%msbuild%" "%solution%" /p:DeployOnBuild=True;Username=username;Password=password;DeployTarget=MSDeployPublish;MsDeployServiceUrl=https://192.168.1.66:8172/msdeploy.axd;Configuration=Release;TargetFramework=v4.5.2;AllowUntrustedCertificate=True;DeployIisAppPath=Faso;MSDeployPublishMethod=WMSVC;SkipExtraFilesOnServer=True;ExcludeFilesFromDeployment="Web.config;ConnectionStrings.config;system.config"'
like image 164
Mark Twain Avatar answered Nov 02 '22 22:11

Mark Twain