【问题标题】:How do I Publish using Azure DevOps?如何使用 Azure DevOps 发布?
【发布时间】:2019-04-07 09:36:05
【问题描述】:

我正在尝试使用 Azure DevOps 为 .NET Core 2.1 示例项目(即开箱即用的默认项目)设置 CI/CD 管道和发布流程。到目前为止,我还没有更改默认代码,也没有在项目中添加/删除任何引用。它正在本地构建和运行,没有任何错误。

我创建了一个简单的构建管道,其中包含还原、构建和发布等任务。

由于某种原因,发布失败并出现以下错误。

##[section]Starting: Publish
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
Version      : 2.149.0
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
==============================================================================
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" publish "D:\a\1\s\Devops Demo\Devops Demo.csproj" --configuration release --output D:\a\1\a\Devops Demo
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB1008: Only one project can be specified.
Switch: Demo

For switch syntax, type "MSBuild /help"
##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
##[error]Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\Devops Demo\Devops Demo.csproj
##[section]Finishing: Publish

我在谷歌上搜索并找到了几个抱怨这个错误的人,但没有人有任何明确的解决方案。

到目前为止,我还没有在我的项目和 CI/CD 配置中尝试过任何花哨的东西。上述错误对我来说是一个障碍,因为我无法继续进行简单的 devops 设置。

如果您对我修复此错误有任何建议,请告诉我。

我的 YAML 如下,

pool:
  name: Hosted VS2017
#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references an undefined variable named ‘Parameters.RestoreBuildProjects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

steps:
- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore
    projects: '$(Parameters.RestoreBuildProjects)'

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '$(Parameters.RestoreBuildProjects)'
    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
    workingDirectory: 'Devops Demo'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'

【问题讨论】:

  • 可能意味着你的fileglob匹配了几个proj文件,让它更严格?
  • 在您的--output 文件夹名称中添加" "
  • 谢谢@4c74356b41,您能否详细说明您的建议。
  • @ShaykiAbramczyk 参数设置为 --configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)。我在哪里添加“”?
  • 好的,我刚刚在日志中看到生成到D:\a\1\a\Devops Demo 的变量,我认为因为Devops Demo 中有一个空格,它可能会导致问题。在workingDirectory 值中,您可以将其更改为“DevopsDemo”吗?或将输出更改为"$(build.artifactstagingdircetory)"

标签: azure-devops azure-pipelines


【解决方案1】:

错误是因为在您的--output D:\a\1\a\Devops Demo 中没有" " 并且值包含空格,所以只需将文件夹名称固定为"D:\a\1\a\Devops Demo"

.yaml 我可以看到您使用变量$(build.artifactstagingdirectory),因此将其更改为"$(build.artifactstagingdirectory)"

【讨论】:

  • 嘿,不错的收获!
猜你喜欢
  • 2020-01-18
  • 2019-03-26
  • 2021-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多