Unable to load the service index for source - c#

I am running into an unauthorized error on an onpremise Devops 2019 build server for a .net core 3.1 solution. It seems the build server cannot access the artifact feed although this works for other solutions. Here is the error:
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" test C:\a\_work\61\s\MySolution\MySolution.csproj --logger trx --results-directory C:\a\_work\_temp
C:\Program Files\dotnet\sdk\3.1.302\NuGet.targets(128,5): error : Unable to load the service index for source https://mydomin/tfs/DefaultCollection/_packaging/MyFeed/nuget/v3/index.json. [C:\a\_work\61\MySolution\MySolution.csproj]
C:\Program Files\dotnet\sdk\3.1.302\NuGet.targets(128,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\a\_work\61\s\MySolution\MySolution.csproj]
and here is the pipeline.yaml file, the error occurs in the DotNetCoreCLI#2 step:
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool: 'Default'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
inputs:
versionSpec: '5.x'
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration $(buildConfiguration) --self-contained true -f netcoreapp3.1 -r win10-x64 --output $(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
Any suggestions how to fix the auth problem?
I tried updating the PAT token for the artifact feed on the build server but without success.
Here is the full error message:
##[section]Starting: DotNetCoreCLI
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.153.3
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
[command]C:\Windows\system32\chcp.com 65001
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" publish C:\a\_work\588\s\MySolution.sln --configuration Release --self-contained true -f netcoreapp3.1 -r win10-x64 --output C:\a\_work\588\a\s
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 292,84 ms for C:\a\_work\588\s\MySolution\MySolution.csproj.
C:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5): error : Unable to load the service index for source https://MyDomain/tfs/DefaultCollection/_packaging/MyFeed/nuget/v3/index.json. [C:\a\_work\588\s\MySolution.sln]
C:\Program Files\dotnet\sdk\3.1.201\NuGet.targets(124,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\a\_work\588\s\MySolution.sln]
##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
##[error]Dotnet command failed with non-zero exit code on the following projects : C:\a\_work\588\s\MySolution.sln
##[section]Finishing: DotNetCoreCLI

Please try to create a PAT in DevOps, and register package feed with personal access token via the command below:
nuget sources add -name {your feed name} -source {your feed URL} -username {anything} -password {your PAT}

Related

How can I build a Docker image in an Azure Devops pipeline while specifying the architecture as linux/arm64/v8?

I currently have an Azure Devops build pipeline that creates an image build on the amd64 architecture. When I try to run this on a Raspberry Pi it fails with an error stating that the image needs to be built using linux/arm64/v8 architecture.
Here is my YAML
trigger:
branches:
include:
- master
paths:
include:
- 'XXXXX/*'
variables:
tag: '$(Build.BuildId)'
dockerrepo: 'xxxxxxx'
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: Docker#2
inputs:
containerRegistry: 'xxxxx Container Registry'
repository: $(dockerrepo)
command: 'buildAndPush'
Dockerfile: '*/Dockerfile'
tags: |
$(tag)
The Docker file builds c# .net6 console app.
How can I get the pipeline to build the image with a specified architecture so that it can run on a Raspberry Pi 4?
EDIT
Also tried supplying platform argument as advised by #szombati_attila but this fails to create an image failing with an invalid argument error
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: Docker#2
inputs:
containerRegistry: 'xxxx Container Registry'
repository: $(dockerrepo)
command: build
arguments: '--platform linux/arm64/v8'
Dockerfile: '*/Dockerfile'
tags: |
$(tag)
- task: Docker#2
inputs:
containerRegistry: 'xxxx Container Registry'
repository: $(dockerrepo)
command: push
Dockerfile: '*/Dockerfile'
tags: |
$(tag)
I would recommend splitting the buildAndPush into two different commands. Because you cannot add any additional argument when you are using the buildAndPush command. This is because the buildAndPush command is a combination of two docker commands (build and push) and the additional argument input would be ambiguous.
After the split, you will have two tasks and the arguments now can be added to the build task.
- task: Docker#2
displayName: BuildDockerContainer
inputs:
command: build
containerRegistry: registry
repository: repo
tags: latest
arguments: add any label that you want here and supported by Docker (--platform linux/amd64,linux/arm64)
- task: Docker#2
displayName: PushDockerImageToRegisitry
inputs:
command: push
containerRegistry: registry
repository: repo
tags: latest
Documentations:
Azure DevOps Docker-V2:
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/docker-v2?view=azure-pipelines&tabs=yaml
Docker platform flag:
https://docs.docker.com/build/building/multi-platform/

Running Playwright dotnet tests on Azure DevOps

I'm trying to execute Playwright dotnet tests with Nunit framework on Azure DevOps. I'm unable to execute testcases as and when I try to install playwright as a part of pipeline, there is an error thrown and build gets failed with the following message
Couldn't find project using Playwright. Ensure a project or a solution
exists in D:\a\1\s, or provide another path using -p.
Below is my azure pipeline steps, Can someone please help me where exactly the issue is and I have tried both Windows and latest Ubuntu agents
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: UseDotNet#2
displayName: 'Install .NET'
inputs:
packageType: 'sdk'
version: '6.0.x'
installationPath: $(Agent.ToolsDirectory)/dotnet
includePreviewVersions: true
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
inputs:
command: 'custom'
custom: 'new'
arguments: 'tool-manifest'
- task: DotNetCoreCLI#2
displayName: 'Installing Playwright Cli'
inputs:
command: 'custom'
custom: 'tool'
arguments: 'install Microsoft.Playwright.CLI'
- task: DotNetCoreCLI#2
displayName: 'Building tests project'
inputs:
command: 'build'
projects: '**/*Tests*.csproj'
- task: DotNetCoreCLI#2
displayName: Run Playwright Install
inputs:
command: custom
custom: 'tool '
arguments: run playwright install
- task: DotNetCoreCLI#2
displayName: 'Run tests'
inputs:
command: 'test'
projects: '**/*Tests*.csproj'
testRunTitle: 'new pipeline'
With Visual Studio projects you can add post-build-events, which will run on you dev machine and in the Azure Pipeline during a build (tested with VSBuild#1)
Example using the VS UI:
(you will need to adjust paths for ubuntu)
echo $(TargetDir).playwright\node\win32_x64\playwright.cmd install
$(TargetDir).playwright\node\win32_x64\playwright.cmd install
echo Done
or adding directly to a .csproj
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo $(TargetDir).playwright\node\win32_x64\playwright.cmd install;$(TargetDir).playwright\node\win32_x64\playwright.cmd install;echo Done" />
</Target>

Azure DevOps Build Pipeline: 'publish' command is executing 'dotnet build' instead of 'dotnet publish'

I have an azure build pipeline that I'm trying to modify to add build and publish and an azure function.
I'm trying to run a 'publish' command using the dotnet cli, but for whatever reason, azure devops is running a 'build' command instead.
My pipeline looks like this:
trigger:
- master
variables:
solution: "**/*.sln"
jobs:
- job: backend_build
- task: DotNetCoreCLI#2
inputs:
commands: "publish"
publishWebProjects: false
projects: "someFunction.csproj"
arguments: "--configuration Release -r win10-x64"
displayName: "Publish someFunction"
- task: PublishPipelineArtifact#1
inputs:
path: "$(System.DefaultWorkingDirectory)/someFunction/bin/Release/netcoreapp3.1/win10-x64/publish.zip"
artifact: "ApplyMigrations"
displayName: "Publish someFunction Function"
But when this pipeline executes, that Publish someFunction task ends up executing dotnet build instead of dotnet publish
47ad-91fc-a4b1d163081b/2.175.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"
2020-10-27T20:36:40.0448279Z ##[debug]/usr/bin/dotnet arg: --configuration Release -r win10-x64
2020-10-27T20:36:40.0454259Z ##[debug]exec tool: /usr/bin/dotnet
2020-10-27T20:36:40.0454556Z ##[debug]arguments:
2020-10-27T20:36:40.0454825Z ##[debug] build
2020-10-27T20:36:40.0455170Z ##[debug] /home/vsts/work/1/s/someFunction.csproj
2020-10-27T20:36:40.0456258Z ##[debug] -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.175.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.175.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"
2020-10-27T20:36:40.0457276Z ##[debug] --configuration
2020-10-27T20:36:40.0457663Z ##[debug] Release
2020-10-27T20:36:40.0463060Z ##[debug] -r
2020-10-27T20:36:40.0463499Z ##[debug] win10-x64
2020-10-27T20:36:40.0465119Z [command]/usr/bin/dotnet build /home/vsts/work/1/s/someFunction.csproj -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.175.0/dotnet-build-helpers
Anyone have any ideas why this might be happening? There are no errors being displayed, it just isn't executing the right command...
Your error is commands: "publish". It should be command, not commands.
Because you have not included a command value, it uses the default value of Build.

When deploying through Azure DevOps getting error: You do not have permission to view this directory or page

When I am deploying the web application using DevOps pipeline I am getting this error: "You do not have permission to view this directory or page." I figured out that when I deploy it manually with the "publish" button there is no initial folder in uploaded files, but when uploaded through Azure DevOps there are initial folders with all the projects, any ideas?
files structure when deployed from "publish" button directly from VS (working)
files structure when deployed from Azure DevOps (not working)
the error: You do not have permission to view this directory or page
when open swagger UI: The resource you are looking for has been removed, had its name changed or is temporarily unavailable.
azure-pipelines.yaml file :
trigger:
- master
pool:
name: Hosted Windows 2019 with VS2019
demands: npm
variables:
buildConfiguration: 'Release'
steps:
- task: Npm#1
displayName: 'angular-cli'
inputs:
workingDir: src/Kronova.MovingPortal.Web.Host
verbose: false
- task: Npm#1
displayName: 'ng build'
inputs:
command: custom
workingDir: src/Kronova.MovingPortal.Web.Host
verbose: false
customCommand: 'run publish-full'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: dist'
inputs:
PathtoPublish: src/Kronova.MovingPortal.Web.Host/wwwroot
ArtifactName: dist
- task: UseDotNet#2
displayName: 'Use .NET SDK 3.1'
inputs:
packageType: 'sdk'
version: '3.1.x'
- task: DotNetCoreCLI#2
displayName: 'Restore project dependencies'
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
displayName: 'Build the project - $(buildConfiguration)'
inputs:
command: 'build'
arguments: '--no-restore --configuration $(buildConfiguration)'
projects: |
**/*.csproj
!**/*Mobile*.csproj
!**/*Client*.csproj
!**Kronova.MovingPortal.Application.Client/**
- task: DotNetCoreCLI#2
displayName: 'Publish the project - $(buildConfiguration)'
inputs:
command: publish
projects: |
**/*.csproj
!**/*Mobile*.csproj
!**/*Client*.csproj
!**Kronova.MovingPortal.Application.Client/**'
publishWebProjects: false
arguments: '--no-build --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
zipAfterPublish: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: Estimated_Pad_Api'
condition: succeeded()
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'Estimated_Pad_Api'
publishLocation: 'Container'

How can I share a built .NET Core project between many jobs in Azure pipelines?

- job: buildAndTestJob
steps:
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
vstsFeed: $(vstsFeed)
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
arguments: '--configuration ${{ parameters.buildConfiguration }}'
- task: DotNetCoreCLI#2
displayName: 'dotnet test'
inputs:
command: test
arguments: '--configuration ${{ parameters.buildConfiguration }}'
- task: CopyFiles#2
displayName: copy bin files
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: '**/bin/**/*'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: CopyFiles#2
displayName: copy obj files
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: '**/obj/**/*'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
displayName: publish build artifacts
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: buildeffect
publishLocation: 'Container'
-job: packAndPushJob
steps:
- task: DownloadBuildArtifacts#0
displayName: download build artifacts
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'buildeffect'
downloadPath: '$(Build.ArtifactStagingDirectory)'
- task: CopyFiles#2
displayName: copy files to source directory
inputs:
sourceFolder: '$(Build.ArtifactStagingDirectory)/buildeffect'
contents: '**/*'
TargetFolder: '$(Build.SourcesDirectory)'
allowPackageConflicts: true
- task: DotNetCoreCLI#2
displayName: 'dotnet pack'
inputs:
arguments: '--no-restore'
nobuild: true
command: pack
projects: '$(Build.SourcesDirectory)'
publishWebProjects: true
publishVstsFeed: $(vstsFeed)
includeNuGetOrg: true
- task: NuGetCommand#2
displayName: 'nuGet push'
inputs:
command: push
projects: '$(Build.SourcesDirectory)'
publishVstsFeed: $(vstsFeed)
allowPackageConflicts: true
I have 2 jobs. First, to restore, test, build and share build files in a build artifact. Second to pack and push nuget packages. First job finished their job with success, but second job failed during pack task. It have a problem with nuget packages, for example:
/usr/share/dotnet/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error NETSDK1064: Package Microsoft.CSharp, version 4.6.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/home/vsts/work/1/s/src/Spotio.Leads.Client/Spotio.Leads.Client.csproj]
So, maybe should we share builded project in another way? Or maybe add some parameters with feeds to restore? I don't have any idea, so please, if you have any suggestions, help us :)
How can I share a built .NET Core project between many jobs in Azure
pipelines?
1.See this : Projects using the PackageReference format always use packages directly from this folder(%userprofile%\.nuget\packages).
2.Project that targets .net core uses PackageReference format, so the restored packages are stored in %userprofile%\.nuget\packages in first agent.
3.For your second agent job, devops actually start another hosted agent to run your tasks. It means for second agent, it doesn't have the referenced packages in %userprofile%\.nuget\packages.
4.Something we should know is that: Though we've copied all files of bin and obj to second agent, dotnet pack xx.csproj will still try to confirm the referenced packages exist, then the issue occurs.
So I suggest you can add a dotnet restore task before that dotnet pack task in second agent job to make sure the missing packages can be found in second agent.
Note:
1.In one build pipeline with two agent jobs, though these two agent jobs all use hosted agent, these two agent is not the same instance.
2.Make sure the configuration you use to build is the same configuration you use to pack.
Hope it helps. If i misunderstand anything, feel free to let me know :)

Categories

Resources