MSBUILD 发布 ERROR_USER_UNAUTHORIZED

Mar*_*ain 5 msbuild publish continuous-delivery gitlab gitlab-ci

概括

我在 Windows Server 2016 上使用 9.2.0 Gitlab 的 CI 多运行器。在我通过 MSBUILD 发布 ASP.NET 项目的步骤中,我收到了ERROR_USER_UNAUTHORIZED来自 IIS的身份验证错误。但是当我CMD在构建机器上使用窗口时,我运行相同的发布命令 - 一切都已发布。我使用的SYSTEMADMINISTRATOR帐户还是帐户都没有关系。

重现步骤

  1. 设置 IIS 发布。
  2. 设置 Gitlab 的构建代理。
  3. 创建 Gitlab 的 YAML 构建脚本(见下文)。
  4. 运行构建。

实际行为

在发布步骤中,我遇到了ERROR_USER_UNAUTHORIZED错误。

预期行为

在发布步骤中,我已将 ASP.NET 发布到服务器。

相关日志和/或屏幕截图

  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]
Run Code Online (Sandbox Code Playgroud)

环境描述

我在 Windows 2016 上使用共享 Runner(gitlab-ci-multi-runner-windows-386,版本 9.2.0)。 MSBUILD 是 Microsoft Visual Studio 2017 的一部分。

YAML 脚本

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
Run Code Online (Sandbox Code Playgroud)

Mar*_*ain 5

通过更改 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"'
Run Code Online (Sandbox Code Playgroud)