azure-devops - 如何使用 yaml 配置从 azure 管道生成特定版本的 nuget 包
问题描述
我在这里定义了一个构建配置:
https://github.com/cpoDesign/APIFramework/blob/master/azure-pipelines.yml
我设法使用以下命令生成了一个 nuget 包
- task: DotNetCoreCLI@2
inputs:
command: pack
projects: '**/*ApiFramework.csproj'
脚本任务输出的一个子集是
Task "PackTask"
2018-11-27T23:02:32.4459067Z Successfully created package '/home/vsts/work/1/a/CPODesign.ApiFramework.1.0.0.nupkg'.
下一步解决:
我不想创建一个发布到 nuget 的构建,因为这些步骤必须在逻辑上分开。因此,我创建了一个新步骤 Create a drop。
配置:
我的放置任务定义:
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
contents: '**/$(BuildConfiguration)/**/?(*.nupkg)'
构建输出:
2018-11-27T23:04:24.6351310Z ##[section]Starting: PublishBuildArtifacts
2018-11-27T23:04:24.6353582Z ==============================================================================
2018-11-27T23:04:24.6353896Z Task : Publish Build Artifacts
2018-11-27T23:04:24.6353944Z Description : Publish build artifacts to Azure Pipelines/TFS or a file share
2018-11-27T23:04:24.6354007Z Version : 1.142.2
2018-11-27T23:04:24.6354046Z Author : Microsoft Corporation
2018-11-27T23:04:24.6354091Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=708390)
2018-11-27T23:04:24.6354156Z ==============================================================================
2018-11-27T23:04:26.1357631Z ##[section]Async Command Start: Upload Artifact
2018-11-27T23:04:26.1357755Z Uploading 1 files
2018-11-27T23:04:26.6373194Z File upload succeed.
2018-11-27T23:04:26.6373313Z Upload '/home/vsts/work/1/a' to file container: '#/1558454/drop'
2018-11-27T23:04:27.9231805Z Associated artifact 91 with build 806
2018-11-27T23:04:27.9231947Z ##[section]Async Command End: Upload Artifact
2018-11-27T23:04:27.9232436Z ##[section]Finishing: PublishBuildArtifacts
注意: azure-devops 的 UI 已更改,工件(工件)不再创建为新选项卡,而是严重添加到报告摘要中
问题:
如何生成特定版本的 nuget 包 IE: 1.0.%(Build.BuildId)?
我的最后一次尝试是
- task: DotNetCoreCLI@2
inputs:
command: pack
projects: '**/*ApiFramework.csproj'
# packageVersion:'1.0.$(Build.BuildId)'
在哪里
packageVersion:'1.0.$(Build.BuildId)'
会导致构建失败(当前分支发布在这里:https ://github.com/cpoDesign/APIFramework/blob/cpoDesign-build-mods-1/azure-pipelines.yml )
解决方案
在令人沮丧的几个小时之后,我找到了答案
- 将生成的 nuget 包发布到构建工件中
- 生成发布以发布 nuget 包
构建配置
pool:
vmImage: 'Ubuntu 16.04'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI@2
inputs:
command: restore
projects: '**/*.csproj'
- script: dotnet test **/*.Tests.Unit.csproj --logger trx
- task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
- script: dotnet pack /p:PackageVersion='1.0.$(Build.BuildId)' --configuration $(buildConfiguration) -o $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
contents: '**/$(BuildConfiguration)/**/?(*.nupkg)'
发布部分
我已更新版本以在每次成功构建后触发
dotnet nuget push artefactName.APIFramework/drop/CPODesign.ApiFramework.1.0.$(Build.BuildId).nupkg -k $(myapiKey) -s https://api.nuget.org/v3/index.json
推荐阅读
- formik - Formik Yup 验证字符串数组不起作用
- microsoft-dynamics - 在 AX 2012 R2 中的装运预订自动位置重新填充
- javascript - 元素的PHP动态id属性
- mongodb - Mongo DB 中的日期格式错误
- python - 数据框行之间的计算
- javascript - Javascript使用while循环查找和替换函数
- r - 在 RShiny 中,当 downloadHandler 中缺少预期文件时,使用 renderPrint/renderText 显示错误
- visual-studio - 为什么 VS2019 的 Go To Implementation 会显示重复的引用?
- r - 如何在 R 中获得单面 HP 过滤器
- python - 将图像旋转到直线方向