I'm trying to run my unit tests with Chrome headless and I need to the install Google Chrome on an Azure agent. I'm wondering how can I do that. I tried a few founds over the net: like this, also with:
steps:
# Install Google Chrome on the virtual machine
- powershell: |
$chromeInstaller = "chrome_installer.exe"
Invoke-WebRequest -Uri "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $chromeInstaller
Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait
Remove-Item -Path $chromeInstaller
displayName: 'Install Google Chrome'
and also with chocolatey, but I'm constantly getting errors. My question is: is there a convinient way to install google chrome browser before other dependencies of my project? And this is windows machine :)
One of the error message I'm getting is:
Starting: choco install googlechrome
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.201.1
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents: shell
choco install googlechrome --ignore-checksums
========================== Starting Command Output ===========================
"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\build-agent1\_work\_temp\126aba93-a820-462a-afb4-9a641c09b1dc.cmd""
'choco' is not recognized as an internal or external command,
operable program or batch file.
##[error]Cmd.exe exited with code '1'.
Finishing: choco install googlechrome
This when I try with choco. I have another one, when I try with a powershell script:
Starting: Install Google Chrome
==============================================================================
Task : PowerShell
Description : Run a PowerShell script on Linux, macOS, or Windows
Version : 2.228.1
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\build-agent1\_work\_temp\53343eda-e728-4087-964a-bade5361f976.ps1'"
Exception calling "DownloadFile" with "2" argument(s): "The remote server returned an error: (503) Server Unavailable."
At D:\build-agent1\_work\_temp\53343eda-e728-4087-964a-bade5361f976.ps1:4 char:70
+ ... aller.exe"; (new-object System.Net.WebClient).DownloadFile('http:/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : WebException
##[error]PowerShell exited with code '1'.
Finishing: Install Google Chrome
My pipeline file:
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- main
pool:
name: M3-build-pool
steps:
Install Google Chrome on the virtual machine
powershell: |
$chromeInstaller = "chrome_installer.exe"
Invoke-WebRequest -Uri "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $chromeInstaller
Start-Process -FilePath $chromeInstaller -ArgumentList "/silent", "/install" -NoNewWindow -Wait
Remove-Item -Path $chromeInstaller
displayName: 'Install Google Chrome'
task: NodeTool@1
inputs:
versionSpec: '22.x'
displayName: 'Install Node.js 22.x'
script: |
npm install
displayName: 'npm install'
script: |
npm run build:webcomponent
displayName: 'npm build:webcomponent'
script:
npm run npm test:once
displayName: 'npm test:once'
task: CopyFiles@2
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
contents: |
main.js
styles.css
targetFolder: '$(Build.ArtifactStagingDirectory)'
displayName: 'Copy project files'
task: PublishPipelineArtifact@1
inputs:
artifactName: m3-webcomponent
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: 'pipeline'
displayName: 'Publish npm artifact'