I am trying to run some unit tests in my azure pipeline but it keeps saying 'Waiting for console output'. This goes on for about an hour until it eventually fails. I do not understand why it can't access the output from console. New to working with Azure/pipelines in general and any help would be appreciated. Thank you.
Here is my yaml file:
pr:
- $(branch)
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.14'
displayName: 'Install Node.js'
- script: |
npm install -g #angular/cli
npm install
displayName: 'Install Angular Dependencies'
- task: Npm#1
displayName: 'Lint Angular'
inputs:
command: custom
customCommand: run lint -- --format=stylish
- script: |
npm run test
displayName: 'Run Unit Tests'
- task: PublishTestResults#2
displayName: 'Publish unit tests results'
condition: succeededOrFailed()
inputs:
searchFolder: $(System.DefaultWorkingDirectory)/src/tests/junit
testRunTitle: Angular
testRunner: JUnit
testResultsFiles: "**/TESTS-*.xml"
- task: PublishCodeCoverageResults#1
displayName: 'Publish unit test code coverage results'
condition: succeededOrFailed()
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(System.DefaultWorkingDirectory)/src/tests/coverage/cobertura-coverage.xml
reportDirectory: $(System.DefaultWorkingDirectory)/src/tests/coverage
failIfCoverageEmpty: true
- script: |
$(npm-script)
displayName: 'Build App'
- script: |
cd $(System.DefaultWorkingDirectory)/
ls -a
cp -r dist $(Build.ArtifactStagingDirectory)/
cp ecosystem.config.js $(Build.ArtifactStagingDirectory)/
cd $(Build.ArtifactStagingDirectory)/
ls -a
# rm -r node_modules
# ls -a
displayName: 'Copy Files to Archive'
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' # '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- script: |
cd $(System.DefaultWorkingDirectory)/
ls -a
cd $(Build.ArtifactStagingDirectory)/
ls -a
displayName: 'Check Files 2'
- task: CopyFiles#2
displayName: 'Copy File to: $(TargetFolder)'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)/'
Contents: '$(Build.ArtifactStagingDirectory)/**/*.zip'
TargetFolder: '$(Build.ArtifactStagingDirectory)/ArtifactsToBePublished'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: App'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/ArtifactsToBePublished'
# - script: |
# npm run pre-e2e
# npm run e2e
# displayName: 'Run E2E Tests'
- script: |
pwd
cd $(Build.ArtifactStagingDirectory)/ArtifactsToBePublished
ls -a
displayName: 'See Content'
I can reproduce the same issue with npm run test script. You can have a try running unit tests with Npm task instead of using script task.
- task: Npm#1
displayName: 'Unit Test'
inputs:
command: custom
customCommand: run test -- --watch=false --code-coverage
Or
- task: Npm#1
displayName: 'Test e2e Angular'
inputs:
command: custom
customCommand: run e2e
I came across with this issue today and, based on this hint, I figured out that the browser was preventing some events from happening. So I disabled my ad blocker—in my case, Brave Shield, because I use Brave browser—and the problem is solved.
Related
Hiall,
I developed a ui test with playwright.
I run this in azure pipeline, when a test is pass, everything is OK, the
steps:
run test - pass
publish artifact - pass
post job - pass
but when i add an error to the test -
await expect(activitiesHeader).toHaveClass("goodclass badclass")
I get an error in pipeline log, it is ok, and reach the timeout too
but the pipeline is stuck in run test step (so the next steps never execute)
my yaml:
task: NodeTool#0
inputs:
versionSpec: '14.x'
displayName: 'Install Node.js'
script: npm install
script: npm ci
script: npm install #playwright/test
script: npx playwright install --with-deps
displayName: "Install browser dependencies"
script: npm i playwright-chromium
displayName: "run the test"
condition: succeeded()
script: npm run azurelogin
task: CopyFiles#1
condition: succeededOrFailed() # Run task even if previous ones fail
inputs:
#leave it empty, the copying is done from the root folder
#sourceFolder: '$(Build.SourcesDirectory)/_daniavander_hydro-test/playwright-report'
contents: |
playwright-report/**
screenshot/**
test-results/**
targetFolder: '$(Build.ArtifactStagingDirectory)'
task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
I have recently needed to run a .CMD script using YAML in Azure DevOps. I can get it to run and put files in the root of $(System.DefaultWorkingDirectory) but I need it to put the files in $(System.DefaultWorkingDirectory)/teacher/website. Every time I try to do this In two different ways I come up short.
I have first tried with this method:
Batch script
Run a Windows command or batch script and optionally allow it to change the environment
- task: BatchScript#1
inputs:
filename: 'scripts/deploy.cmd'
arguments: # Optional
modifyEnvironment: False # Optional
workingFolder: $(Build.ArtifactStagingDirectory)/teacher/website # Optional
failOnStandardError: false # Optional
This way will just put the files in the $(Build.ArtifactStagingDirectory) which is not what I want, as I have some .Net Build files going there.
I then tried this way:
- script: 'scripts/deploy.cmd' # script path or inline
workingDirectory: '$(Build.ArtifactStagingDirectory)/teacher/website'
displayName: run deploy.cmd
#failOnStderr: #
#env: # mapping of environment variables to add
This way I get an error that says: ##[error]Container path not found: C:\azp\agent\_work\17\a\Teacher\website
I am trying to build all this into an artefact and then that artefact is later deployed to the web app. Here is my fully YAML file so you have an idea of what I am doing:
parameters:
- name: buildConfiguration
type: string
default: 'Release'
- name: project
type: string
default: 'Teacher.csproj'
- name: artifactName
type: string
default: 'Teacher'
jobs:
- job:
pool:
name: 'DotNet6_Terraform'
steps:
- checkout: Teacher
submodules: true
- task: CmdLine#2
displayName: make the Teacher Folder
inputs:
script: 'mkdir Teacher'
workingDirectory: $(Build.ArtifactStagingDirectory)
- task: CmdLine#2
displayName: make website directory
inputs:
script: 'mkdir website'
workingDirectory: $(Build.ArtifactStagingDirectory)/Teacher
- task: CmdLine#2
displayName: Check for folders
inputs:
script: |
echo '$(Build.ArtifactStagingDirectory)/Teacher'
echo '$(Build.ArtifactStagingDirectory)/Teacher/website'
- task: CmdLine#2
displayName: show directory tree
inputs:
script: |
cd '$(System.DefaultWorkingDirectory)/Teacher'
dir
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
projects: 'Teacher/**/*.csproj'
- task: CmdLine#2
displayName: checking dotnet versions
inputs:
script: |
dotnet --list-sdks
dotnet --list-runtimes
- task: CmdLine#2
displayName: dotnet build
inputs:
script: |
dotnet build Teacher/Teacher.csproj --configuration Release
- task: DotNetCoreCLI#2
displayName: 'Publish Application'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/*.csproj'
arguments: '--configuration ${{ parameters.buildConfiguration }} --output $(Build.ArtifactStagingDirectory)/Teacher'
publishTestResults: false
zipAfterPublish: true
modifyOutputPath: false
workingDirectory: Teacher
- task: PowerShell#2
displayName: List Files Post Publish
inputs:
targetType: inline
script: Get-ChildItem -path '$(Build.ArtifactStagingDirectory)/Teacher'
- script: 'scripts/deploy.cmd' # script path or inline
workingDirectory: '$(Build.ArtifactStagingDirectory)/Teacher/website'
displayName: run deploy.cmd
#failOnStderr: #
#env: # mapping of environment variables to add
# Batch script
# Run a Windows command or batch script and optionally allow it to change the environment
#- task: BatchScript#1
# inputs:
# filename: 'scripts/deploy.cmd'
#arguments: # Optional
#modifyEnvironment: False # Optional
# workingFolder: $(Build.ArtifactStagingDirectory)/Teacher/website # Optional
# failOnStandardError: false # Optional
- task: PublishPipelineArtifact#1
displayName: 'Publish Artifacts'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: ${{ parameters.artifactName }}
publishLocation: 'pipeline'
I have a react app, created with npx create-react-app command, and configured a yaml based azure devops pipeline for CI/CD. Then I added some simple unit tests.
I added a script task in my yaml pipeline to generate coverage results as follows.
- script: |
cd reactonazure
npm run test -- --coverage --ci --reporters=default --reporters=jest-junit --coverageReporters=cobertura
displayName: 'test code coverage'
But this tasks displays the following output and then task continues to run and never ends. I have to cancel the pipeline run to ultimately stop it. Not sure whats happening. Any ideas?
No tests found related to files changed since last commit.
But when I prefix with CI=true to make the command as follows, then the command works fine and I get test results, but no where I find coverage report(cobertura-coverage.xml).
CI=true npm test -- --reporters=jest-junit --reporters=default --coverageReporters=cobertura
I added a simple script task shown below to list out the files and folders to enable me search for cobertura-coverage.xml. But no where I found the file. Note that jest.xml file is being created. And that is the reason why I am able to see the test results shown above. The problem is with test coverage report.
- script: |
pwd
cd ..
pwd
ls -Rla
displayName: 'list out the files and folders for inspection'
Also when I run the following command on vs code command prompt on my machine(Windows 10), I do see a file named cobertura-coverage.xml in coverage folder.
npm run test -- --coverage --ci --reporters=default --reporters=jest-junit --coverageReporters=cobertura
The full pipeline yaml is pasted below.
trigger:
- master
variables:
azureSubscription: 'AzureServiceConnection'
# Web app name
webAppName: BasicReactApp
# Environment name
environmentName: Dev
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: NodeTool#0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js'
- script: |
cd reactonazure
npm install
npm run build --if-present
displayName: 'npm install, build '
- script: |
cd reactonazure
CI=true npm test -- --reporters=jest-junit --reporters=default --coverageReporters=cobertura
displayName: 'test code coverage'
- task: PublishTestResults#2
displayName: "Publish Test Results"
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: 'reactonazure/junit.xml'
failTaskOnFailedTests: true
mergeTestResults: true
condition: succeededOrFailed()
# The following, two are not functioning as no coverage.cobertura.xml file is being created.
- task: PublishCodeCoverageResults#1
displayName: "Publish code coverage"
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: "reactonazure/$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml"
reportDirectory: "reactonazure/$(System.DefaultWorkingDirectory)/coverage"
failIfCoverageEmpty: false
- task: PublishCodeCoverageResults#1
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
failIfCoverageEmpty: true
Are there any other ways to generate report on the pipeline?
The path you provided to the coverage file is incorrect. It should be $(System.DefaultWorkingDirectory)/reactonazure/coverage/cobertura-coverage.xml.
The task would look like this:
- task: PublishCodeCoverageResults#1
displayName: "Publish code coverage"
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: "$(System.DefaultWorkingDirectory)/reactonazure/coverage/cobertura-coverage.xml"
reportDirectory: "$(System.DefaultWorkingDirectory)/reactonazure/coverage"
failIfCoverageEmpty: false
The command to generate the report that I presented earlier is not working. The following is finally working.
CI=true npm run test -- --coverage --watchAll=false --ci --reporters=default --reporters=jest-junit --coverageReporters=cobertura
The full and final yaml after taking into account the suggested answer is below.
trigger:
- master
variables:
azureSubscription: 'AzureServiceConnection'
webAppName: BasicReactApp
environmentName: Dev
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: NodeTool#0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js'
- script: |
cd reactonazure
npm install
npm run build --if-present
displayName: 'npm install, build '
- script: |
cd reactonazure
CI=true npm run test -- --coverage --watchAll=false --ci --reporters=default --reporters=jest-junit --coverageReporters=cobertura
displayName: 'Test with code coverage'
- task: PublishTestResults#2
displayName: "Publish Test Results"
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: 'reactonazure/junit.xml'
failTaskOnFailedTests: true
mergeTestResults: true
condition: succeededOrFailed()
- task: PublishCodeCoverageResults#1
displayName: "Publish code coverage"
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: "$(System.DefaultWorkingDirectory)/reactonazure/coverage/cobertura-coverage.xml"
reportDirectory: "$(System.DefaultWorkingDirectory)/reactonazure/coverage"
failIfCoverageEmpty: false
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/reactonazure/build'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: $(environmentName)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy'
inputs:
azureSubscription: $(azureSubscription)
#appType: webAppLinux
appType: webApp
appName: $(webAppName)
runtimeStack: 'NODE|16.x'
package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
startUpCommand: 'npm run start'
I have created the below YAML file with the PublishTestResults task to display the mocha test results in Azure DevOps portal
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.14.1'
displayName: 'Install Node.js'
- script: |
npm install
mocha test --reporter mocha-junit-reporter
npm test
displayName: 'npm install and test'
- task: PublishTestResults#2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '**/TEST-RESULTS.xml'
- task: ArchiveFiles#2
displayName: 'Archive $(System.DefaultWorkingDirectory)'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/node.zip'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
but whenever I run the build I am getting the following warning
"No test result files matching **/TEST-RESULTS.xml were found."
The main motive is to display the mocha test results separately in a dashboard or a test tab. So that we don't have to check the test task in build process to see the test results.
I encountered same issue,
After trying bunch of things could solve it as below.
Step 1. Update package.json
Include in scripts section:
"test": "cross-env CI=true react-scripts test --env=jsdom
--testPathIgnorePatterns=assets --reporters=default --reporters=jest-junit"
Include below in jest config or jest section in package.json
"jest-junit": {
"suiteNameTemplate": "{filepath}",
"outputDirectory": ".",
"outputName": "junit.xml"
}
Run npm run test locally and see if junit.xml is created.
Step 2. In Azure Pipeline YAML file
Include an Npm task with custom command as below
- task: Npm#1
displayName: 'Run Tests'
inputs:
command: 'custom'
workingDir: "folder where your package.json exists"
customCommand: 'test'
Task to publish Results
- task: PublishTestResults#2
displayName: 'Publish Unit Test Results'
condition: succeededOrFailed()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/junit.xml'
mergeTestResults: true
failTaskOnFailedTests: true
testRunTitle: 'React App Test'
Publish Test Results
When running a build for storybook via an Azure devops pipeline I get the above mentioned error.
I've tried to completely remove this package(plottable) from my project but I keep getting this error and it causes my webpack build to get stuck.
This error doesn't occur locally.
My pipeline:
trigger:
batch: true
branches:
include:
- master
stages:
- stage: develop_build_deploy_stage
pool:
name: Default
demands:
- msbuild
- visualstudio
jobs:
- job: develop_build_deploy_job
steps:
- checkout: self
clean: true
persistCredentials: true
- task: NodeTool#0
displayName: Install Node
inputs:
versionSpec: '12.x'
- task: PowerShell#2
displayName: 'Install Dependencies'
inputs:
targetType: 'inline'
script: |
npm install
- task: PowerShell#2
displayName: 'Increment version'
inputs:
targetType: 'inline'
script: |
git checkout master
git pull origin master
git config --global user.email "d#gmail.com"
git config --global user.name "Build Agent"
npm version patch -m "Increment Version [skip ci]" --force
git push
- task: PowerShell#2
displayName: 'Build Project'
inputs:
targetType: 'inline'
script: |
npm run build-storybook
npm run build
- task: CopyFiles#2
displayName: 'Copy storybook-static Files'
inputs:
sourceFolder: '$(Build.SourcesDirectory)/storybook-static'
contents: '**'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish storybook-static Files to ArtifactStagingDirectory'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: Storybook
- task: S3Upload#1
displayName: 'Upload storybook-static to S3'
inputs:
awsCredentials: 'my-s3'
regionName: 'us-east-1'
bucketName: 'my-s3-bucket'
sourceFolder: $(Build.ArtifactStagingDirectory)
- task: Npm#1
displayName: 'Publish to Feed'
inputs:
command: 'publish'
publishRegistry: 'useFeed'
publishFeed: '#####'
How would I go about resolving this problem?
I still don't know what caused this to be the case but for some reason the changes I had made on my branch weren't being picked up and an import that I had removed wasn't removed on the branch that was being built on.
So in the end it was trying to import a package which I had removed as a dependency.