Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

azure-devops - Azure DevOps将Nuget发布到托管供稿(Azure DevOps publish Nuget to hosted feed)

I have a question using the hosted (free) AzureDevops pipelines.

(我对使用托管(免费)AzureDevops管道有疑问。)

I have a small .NET Core project which I want to create an Azure Devops pipeline where the following is done

(我有一个小型的.NET Core项目,我想创建一个Azure Devops管道,完成以下操作)

  • restore

    (恢复)

  • build

    (建立)

  • pack

    (包)

  • push (to AzureDevOps hosted artifact feed)

    (推送(到AzureDevOps托管的工件提要))

I have the following feed setup on my project in Azure Devops

(我在Azure Devops中的项目上具有以下供稿设置)

在此处输入图片说明

Which has this connection information for the feed

(哪个具有此提要的连接信息)

..../NugetProjects/_packaging/nugetprojectstestfeed/nuget/v3/index.json

It also has the following security applied to it (note the Project Collection Build Service is set as "Contributor")

(它还具有以下安全性(请注意,Project Collection Build Service设置为“ Contributor”))

在此处输入图片说明

Which is as stated from this paragraph from Microsoft official docs

(正如微软官方文档中本段所述)

To publish to an Azure Artifacts feed, set the Project Collection Build Service identity to be a Contributor on the feed.

(若要发布到Azure Artifacts feed,请将Project Collection Build Service身份设置为该Feed的贡献者。)

I then have this build pipeline setup (Yaml)

(然后,我有此构建管道设置(Yaml))

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'
  Major: '1'
  Minor: '0'
  Patch: '0'

steps:

- task: DotNetCoreCLI@2
  displayName: 'Restore'
  inputs:
    command: restore
    projects: '**/MathsLib.csproj'


- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    command: build
    projects: '**/MathsLib.csproj'
    arguments: '--configuration Release' # Update this to match your need


- task: DotNetCoreCLI@2
  inputs: 
    command: 'pack'
    projects: '**/MathsLib.csproj'
    outputDir: '$(Build.ArtifactStagingDirectory)'
    versioningScheme: 'byPrereleaseNumber'
    majorVersion: '1'
    minorVersion: '0'
    patchVersion: '0'


- task: NuGetAuthenticate@0
  displayName: 'NuGet Authenticate'
- task: NuGetCommand@2
  displayName: 'NuGet push'
  inputs:
    command: push
    publishVstsFeed: 'nugetprojectstestfeed'
    allowPackageConflicts: true

The entire pipeline works fine up until the Nuget push.

(整个管道工作正常,直到Nuget推送为止。)

As shown here

(如图所示)

在此处输入图片说明

But if I look into the exception I see this sort of thing

(但是如果我查看异常,我会看到这种情况)

##[warning]Could not create provenance session: {"statusCode":500,"result":{"$id":"1","innerException":null,"message":"The feed with ID 'nugetprojectstestfeed' doesn't exist.","typeName":"Microsoft.VisualStudio.Services.Feed.WebApi.FeedIdNotFoundException, Microsoft.VisualStudio.Services.Feed.WebApi","typeKey":"FeedIdNotFoundException","errorCode":0,"eventId":3000}}
[command]/usr/bin/mono /opt/hostedtoolcache/NuGet/4.1.0/x64/nuget.exe push /home/vsts/work/1/a/MathsLib.1.0.0-CI-20191114-115941.nupkg -NonInteractive -Source https://pkgs.dev.azure.com/XXXXX/_packaging/nugetprojectstestfeed/nuget/v3/index.json -ApiKey VSTS -Verbosity Detailed
System.AggregateException: One or more errors occurred. (Unable to load the service index for source https://pkgs.dev.azure.com/XXXXX/_packaging/nugetprojectstestfeed/nuget/v3/index.json.) ---> NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://pkgs.dev.azure.com/XXXXX/_packaging/nugetprojectstestfeed/nuget/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found - The feed with ID 'nugetprojectstestfeed' doesn't exist. (DevOps Activity ID: F123AC3A-8E75-4D3A-B3B6-60EC4510FF54)).

This was my original feed connection

(这是我最初的提要)

https://pkgs.dev.azure.com/XXXX/NugetProjects/_packaging/nugetprojectstestfeed/nuget/v3/index.json

But this is what is shown in the error message

(但这就是错误消息中显示的内容)

https://pkgs.dev.azure.com/XXXXX/_packaging/nugetprojectstestfeed/nuget/v3/index.json

So it looks like its trying to access a feed in some root project, not the "NuGetProjects" project that I have setup in Azure DevOps.

(因此,看起来它试图访问某个根项目中的提要,而不是我在Azure DevOps中设置的“ NuGetProjects”项目。)

Is there some setting/config that I am missing to tell it to target the feed inside the "NuGetProjects" project

(我是否缺少一些设置/配置来告诉它定位“ NuGetProjects”项目中的提要)

As I say it looks like its looking for some top level feed not inside the specific project for which the build pipeline is setup for

(正如我所说的,它似乎是在为构建管道为其设置的特定项目中寻找一些顶级提要)

Full step by step of using a new feed

(逐步使用新的Feed)

So for completeness here is a full run down of how I created the project the feed and where it sits in the organisation of things (I have created a new feed as suggested as something to try)

(因此,为了完整起见,这里完整介绍了我如何创建项目供稿以及它在事物组织中的位置(我尝试创建一个新的供稿,作为建议的尝试))

I have this organisation "sachabarber2019", which has these projects in it

(我有一个组织“ sachabarber2019”,其中包含这些项目)

在此处输入图片说明

I have then created this feed in one of the projects of the organisation

(然后,我在组织的一个项目中创建了此提要)

在此处输入图片说明

With these settings

(使用这些设置) 在此处输入图片说明

在此处输入图片说明

And this is current build pipeline

(这是当前的构建管道)

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'
  Major: '1'
  Minor: '0'
  Patch: '0'

steps:

- task: DotNetCoreCLI@2
  displayName: 'Restore'
  inputs:
    command: restore
    projects: '**/MathsLib.csproj'


- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    command: build
    projects: '**/MathsLib.csproj'
    arguments: '--configuration Release' # Update this to match your need


- task: DotNetCoreCLI@2
  inputs: 
    command: 'pack'
    projects: '**/MathsLib.csproj'
    outputDir: '$(Build.ArtifactStagingDirectory)'
    versioningScheme: 'byPrereleaseNumber'
    majorVersion: '1'
    minorVersion: '0'
    patchVersion: '0'


- task: NuGetCommand@2
  displayName: 'NuGet push'
  inputs:
    command: push
    feedsToUse: select
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    vstsFeed: anotherfeed
    nuGetFeedType: internal
    publishVstsFeed: anotherfeed
    allowPackageConflicts: true


And as before I get the same error

(和以前一样,我遇到了同样的错误)

##[section]Starting: NuGet push
==============================================================================
Task         : NuGet
Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
Version      : 2.161.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/nuget
==============================================================================
Caching tool: NuGet 4.1.0 x64
Found tool in cache: NuGet 4.1.0 x64
Resolved from tool cache: 4.1.0
Using version: 4.1.0
Found tool in cache: NuGet 4.1.0 x64
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
Detected NuGet version 4.1.0.2450 / 4.1.0
##[warning]Could not create provenance session: {"statusCode":500,"result":{"$id":"1","innerException":null,"message":"The feed with ID 'anotherfeed' doesn't exist.","typeName":"Microsoft.VisualStudio.Services.Feed.WebApi.FeedIdNotFoundException, Microsoft.VisualStudio.Services.Feed.WebApi","typeKey":"FeedIdNotFoundException","errorCode":0,"eventId":3000}}
[command]/usr/bin/mono /opt/hostedtoolcache/NuGet/4.1.0/x64/nuget.exe push /home/vsts/work/1/a/MathsLib.1.0.0-CI-20191120-121118.nupkg -NonInteractive -Source https://pkgs.dev.azure.com/sachabarber2019/_packaging/anotherfeed/nuget/v3/index.json -ApiKey VSTS -Verbosity Detailed
NuGet Version: 4.1.0.2450
mono-sgen: /home/vsts/work/_tasks/NuGetCommand_333b11bd-d341-40d9-afcf-b32d5ce6f23b/2.161.0/CredentialProvider/CredentialProvider.TeamBuild.exe -uri https://pkgs.dev.azure.com/sachabarber2019/_packaging/anotherfeed/nuget/v3/index.json -nonInteractive -verbosity detailed
mono-sgen: URI Prefixes:
mono-sgen:     https://dev.azure.com/sachabarber2019/
mono-sgen:     https://pkgs.dev.azure.com/sachabarber2019/
mono-sgen:     https://pkgsproduks1.pkgs.visualstudio.com/
mono-sgen:     https://pkgs.dev.azure.com/sachabarber2019/
mono-sgen:     https://sachabarber2019.pkgs.visualstudio.com/
mono-sgen:     https://pkgs.dev.azure.com/sachabarber2019/
mono-sgen: URI: https://pkgs.dev.azure.com/sachabarber2019/_packaging/anotherfeed/nuget/v3/index.json
mono-sgen: Is retry: False
mono-sgen: Matched prefix: https://pkgs.dev.azure.com/sachabarber2019/
System.AggregateException: One or more errors occurred. (Unable to load the service index for source https://pkgs.dev.azure.com/sach

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have missed setting some required arguments in your NuGetCommand@2 task.

(您错过了在NuGetCommand @ 2任务中设置一些必需参数的过程。)

Try this:

(尝试这个:)

- task: NuGetCommand@2
  displayName: 'NuGet push'
  inputs:
    command: push
    feedsToUse: select
    vstsFeed: nugetprojectstestfeed
    nuGetFeedType: internal
    publishVstsFeed: nugetprojectstestfeed
    allowPackageConflicts: true

If we look into the documentation of NuGet task, for 'push' command certain arguments are required.

(如果我们查看NuGet任务的文档 ,则对于“ push”命令,某些参数是必需的。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[3] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

56.8k users

...