Running Playwright dotnet tests on Azure DevOps - c#

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>

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/

Azure DevOps YAML Pipeline fails with "A sequence was not expected"

I've been attempting to create a YAML pipeline in Azure DevOps (Version Dev17.M153.3).
I created a simple Hello World C# console app and checked it into our locally hosted Azure-Git repo. I created my azure-pipelines.yml file and have tried various combinations of things in it including:
The ".NET Desktop" configuration
The "Starter Pipeline" configuration
A file from another C# project that I know works
A file form another project, with various mods to match my test project
A completely commented-out file
A completely blank file
However, every time I try to do a build, I get the following failure message:
/azure-pipelines.yml (Line: 1, Col: 1): A sequence was not expected
Given the error always occurs on line 1 and I've tried lots of different content in the file, I think something else must be configured incorrectly, rather than a problem with the YAML.
Does anyone have any ideas what I'm doing wrong, please?
Various Google searches find pages with similar errors, but none of the solutions helped me.
*** Edited to add various YAML file attempts:
I currently have a completely empty YAML file, but still get the error.
Previous files have included:
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '.'
---------------------------------
variables:
solution: 'HelloWorldCsharpSandpit.sln'
- task: VSBuild#1
displayName: 'Build solution (debug)'
inputs:
solution: '$(solution)'
vsVersion: 16.0
platform: x86
configuration: Debug
clean: true
timeoutInMinutes: 10
---------------------------------
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# [Link removed to avoid odd formatting.]
trigger:
- master
pool:
name: 'Default'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
---------------------------------
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
#
#trigger:
#- master
#
#pool:
# name: 'Default'
#
#variables:
# solution: '**/*.sln'
# buildPlatform: 'Any CPU'
# buildConfiguration: 'Release'
#
#steps:
#- task: NuGetToolInstaller#0
#
#- task: NuGetCommand#2
# inputs:
# restoreSolution: '$(solution)'
#
#- task: VSBuild#1
# inputs:
# solution: '$(solution)'
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
#
#- task: VSTest#2
# inputs:
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
---------------------------------
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
You have here mixed few pipelines.
Here is one:
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# [Link removed to avoid odd formatting.]
trigger:
- master
pool:
name: 'Default'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSBuild#1
displayName: 'Build solution (debug)'
inputs:
solution: '$(solution)'
vsVersion: 16.0
platform: x86
configuration: Debug
clean: true
timeoutInMinutes: 10
Here another but commented:
---------------------------------
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
#
#trigger:
#- master
#
#pool:
# name: 'Default'
#
#variables:
# solution: '**/*.sln'
# buildPlatform: 'Any CPU'
# buildConfiguration: 'Release'
#
#steps:
#- task: NuGetToolInstaller#0
#
#- task: NuGetCommand#2
# inputs:
# restoreSolution: '$(solution)'
#
#- task: VSBuild#1
# inputs:
# solution: '$(solution)'
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
#
#- task: VSTest#2
# inputs:
# platform: '$(buildPlatform)'
# configuration: '$(buildConfiguration)'
And once more:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
If you modify you pipeline on the portal you can validate using this button:
Then you will get feedback if all is fine with your pipeline.
If you still have this issue
delete your pipeline from portal
delete your file from repo
start with template from portal
run it
adjust it to your need on portal and validate before saving changes

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 :)

How to upgrade azure CI to use c# 8.0

I have an azure pipeline that builds my asp.net core 2.2 project. I upgraded the project use c# 8.0. However, my azure pipelines don't seem to support c# 8.0. How do I upgrade my azure pipeline to use c# 8.0?
I have looked through the options in the azure pipeline and have not found anything on upgrading to c# 8.0
Here is the generated YAML file
pool:
name: Hosted VS2017
demands:
- msbuild
- visualstudio
steps:
- task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
vstsFeed: '3e219c03-bc0d-4106-82be-9ff3b21190a5'
- task: VSBuild#1
displayName: 'Build solution'
inputs:
solution: '$(Parameters.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: VSTest#2
displayName: 'Test Assemblies'
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\*test*.dll
!**\obj\**
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: True
enabled: false
- task: PublishSymbols#2
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
PublishSymbols: false
continueOnError: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'
condition: succeededOrFailed()
I expect the project to build, but it gives me this error:
CSC : error CS1617: Invalid option '8.0' for /langversion. Use '/langversion:?' to list supported values.
I figured out the issue. Based on the YAML file, I am using the "Hosted 2017" agent pool. After I changed this to "Azure Pipelines" with the "windows-2019" specification, it worked.

Categories

Resources