Azure pipeline - resize: can't open terminal /dev/tty - node.js

I am trying to deploy a little node app using Azure devops.
It's a nuxt app which exits on the line
resize: can't open terminal /dev/tty
My script is currently
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'

Azure pipeline - resize: can't open terminal /dev/tty
The error you got is similar to this one, so the issue seems not to come from the Node Tools Installer task and npm commands above.
Try adding the -tt switch for your ssh command. And if convenient, you can install one self-hosted agent with Interactive mode to check whether the pipeline can runs successfully.
For more details about build/deploy node.js you can check this document.

Related

The app build failed to produce artifact folder Angular Azure Static Web App Deployment Issue

When i try to build angular app using azure devops and deploy to azure static web app i'm receiving below error
The app build failed to produce artifact folder: 'dist/harmony-front'. Please
ensure this property is configured correctly in your deployment
configuration file.
I tried by changing output_location to / , dist, /dist , dist/harmony-front,
nothing seems to work
here's the yaml code for the deployment section
- task: AzureStaticWebApp#0
inputs:
app_location: "/"
api_location: "api"
output_location: "./dist/harmony-front"
app_build_command: 'npm run build:prod'
skip_api_build: true
verbose: true
env:
continueOnError: true
CUSTOM_BUILD_COMMAND: "npm install --force"
azure_static_web_apps_api_token: $(deployment_token)
What was the mistake i made
Thanks
I have tried to repro the same and got positive results after following the below steps.
Step 1: Create a simple angular project and build the project on a local machine and inspect the dist folder.
Step 2: Push the code to Azure Repos.
Step 3: Create azure pipeline as shown below.
trigger: none
pool:
vmImage: ubuntu-latest
steps:
- task: NodeTool#0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'
- script: |
npm install -g #angular/cli
displayName: 'install angular cli'
- task: Npm#1
inputs:
command: 'install'
displayName: 'npm install'
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'run build'
displayName: 'npm build'
- task: Bash#3
inputs:
targetType: 'inline'
script: |
pwd
ls -l
ls -l dist/
- task: AzureStaticWebApp#0
displayName: 'Deploy Azure static webapp'
inputs:
app_location: '/'
output_location: 'dist/my-app'
env:
azure_static_web_apps_api_token: $(static-webapp-token)
Step 4: Verify the result.
If you are still facing that issue, verify the AzureStaticWebApp#0
output location path in angular.json file as below. Both paths must be exact.
Actually I found the issue and will post for future reference. if someone had the same issue.
issue start when you override build command using CUSTOM_BUILD_COMMAND will overwrite the RUN_BUILD_COMMAND so based on the comment of the issue posted on Github instead of npm install --force command combined with build like npm install --force && npm run build works like charm

Azure pipeline: could not extract archive

I have an Azure pipeline that is supposed to build a project and copy the jar to Artifactory. Here is the yml that is supposed to install node:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
I can't get it to run. It fails with
Could not extract archive:
'/home/abc-vsts-user/.m2/repository/com/github/eirslett/node/10.14.2/node-10.14.2-linux-x64.tar.gz':
Input is not in the .gz format
I don't understand why it thinks a file in .gz format is not in .gz format!
While your educating me, could you explain what /home/abc-vsts-user is? Is that an Azure virtual machine? An Artifactory VM? The only place (that I know of) where that file is located is in Artifactory.
Any suggestions?
EDIT
Here is the agent:
pool:
name: jvdc-static-pool
demands:
- Agent.Name -equals jvdc-agent-2
It turned out to be due to having an npm install script also in the same pipeline.
- script: |
npm install
npm run build --if-present
npm run test --if-present
displayName: 'Npm install, build, and test'
That was causing a second attempt at installing node when all that was necessary was
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'

UI tests in Azure pipelines displays error cannot find chrome binary using node js

I am trying to run UI tests in Azure devops pipelines and I created the yaml file and added the command to run UItests on chrome, but gets an error "WebDriverError: unknown error: cannot find Chrome binary"
I am using node js code
Here is the YAML file:
# 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:
name: 'Default'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
- task: Npm#1
inputs:
command: 'install'
customCommand: 'iocContainer'
displayName: 'npm iocContainer'
- task: CmdLine#2
inputs:
script: '.\runUITest.bat "#RecieveOnlineOrder"'
WebDriverError: unknown error: cannot find Chrome binary
The problem seems to be that the chrome driver cannot find the chrome.exe file.
Since you are using the self-hosted agent, you need to make sure you have installed Chrome on your local machine firstly. If only the chrome driver is installed, you will face this issue.
You could also try to update the chrome driver to the latest.
If you have install the Chrome, you could check the file path of chrome.exe.
As per the ChromeDriver - Requirements:
On the other hand, this issue may be related to the version of chrome, this is an open ticket with similar issues, you could refer to it.
You could try to run the following script and check if it could work:
npm i chromedriver --chromedriver_version=LATEST --save-dev

Why is test automation only partially successful with Cypress and Azure DevOps?

I am using Cypress.io (Version 5.1.0) for testing my project.
My project is in azure DevOps. Now i want to include my cypress tests in Azure DevOps so my tests will run automatically.
I set up the JUnit reporter on my Cypress project:
into my “package.json” file i added
"cypress-multi-reporters": "^1.2.4",
"mocha-junit-reporter": "^1.23.3"
then run
npm install
than added
"scripts": {
"scripts": "cypress run",
"test": "npm run scripts"
}
Into my “cypress.json” file i added
"reporter": "mocha-junit-reporter",
"reporterOptions": {
"mochaFile": "cypress/reports/junit/test-results.[hash].xml",
"testsuitesTitle": false
}
After this I created a new Pipeline using Azure Repos in Azure DevOps.
For Pipeline Configuration i selected Node.js.
Now I have a YAML file. Here i removed npm build from the first script.
Now I picked npm from the assisstant. On the npm configurations, I selected custom and write the command run test . Now I Select the result format as “JUnit” and set Test results files to “*.xml”
At last I selected the option "Merge test results".
Now I saved and run the pipeline.
This is what my Job does:
Pool: Azure Pipelines
Image: ubuntu-latest
Agent: Hosted Agent
Started: Yesterday at 17:31
Expanded: Object
Result: True
Evaluating: not(containsValue(job['steps']['*']['task']['id'], '6d15af64-176c-496d-b583-fd2ae21d4df4'))
Expanded: not(containsValue(Object, '6d15af64-176c-496d-b583-fd2ae21d4df4'))
Result: True
Evaluating: resources['repositories']['self']['checkoutOptions']
Result: Object
Finished evaluating template 'system-pre-steps.yml'
********************************************************************************
Template and static variable resolution complete. Final runtime YAML document:
steps:
- task: 6d15af64-176c-496d-b583-fd2ae21d4df4#1
inputs:
repository: self
MaxConcurrency: 0
What is wrong with my automation? How can I fix this?
Update:
Thats my yml file:
# 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.x'
displayName: 'Install Node.js'
- script: |
npm install
displayName: 'npm install'
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'run test'
continueOnError: true
- task: PublishTestResults#2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/cypress/reports/junit'
mergeTestResults: true
testRunTitle: 'Publish Test Results'
I got an email with this Details
Job 1 error(s), 1 warning(s) Error: Npm failed with return code: 254
The issue may be due to the agent rather than your code and scripts.
You can try the following solutions:
Change your agent image. As you are currently using the ubuntu-latest, it is recommanded to try the ubuntu-20.04 or ubuntu-16.04.
Use a self-hosted agent. If you don't have a self-hosted agent, click Self-hosted Linux agent for detailed steps.
Change the orgnization. Choose another organization that can run the build correctly, and just in case, it is better to create a new organization. Then create a new project and try your tests.
As stated already, the problem most likely lies with the Azure environment. Cypress has a dependency on a browser (electron, chrome) in order to execute. For example, if you are using docker, they provide an official image called cypress/browsers:node14.7.0-chrome84 that has everything you need out of the box. The Dockerfile also has useful info on the environment needed. Make sure to provide a headless configuration as well, something like:
cypress run --headless --browser chrome --spec yourSpecHere.js

Visual Studio Team Services Build yml npm test not recognized

I'm trying to run an npm install and test on Visual Studio Team Services Build (configuring the build using YAML). I have the following definition.
** updated **
queue:
name: Hosted VS2017
demands: npm
steps:
- task: NodeTool#0
inputs:
versionSpec: "8.x"
task: Npm#1
inputs:
command: "custom"
verbose: "false"
customCommand: "install #angular/cli -g"
task: Npm#1
inputs:
verbose: "false"
task: CmdLine#1
inputs:
filename: "ng"
arguments: "test --watch=false --single-run=true --reporters=junit,progress"
task: PublishTestResults#2
inputs:
testResultsFiles: "**\test.xml"
testRunTitle: "Jasmine Tests"
The install runs fine, but I get an error on the test step:
85% chunk id optimization 86% hashing 87% module assets processing 88% chunk assets processing 89% additional chunk assets processing 90% recording 91% additional asset processing 92% chunk asset optimization 94% asset optimization 95% emitting
2017-12-06T06:21:34.7643927Z ##[error]Process completed with exit code 1.
2017-12-06T06:21:34.7682485Z ##[section]Finishing: Run Tests
I'm using puppeteer to workaround lack of chrome to run the tests.
Using this code instead:
queue: Hosted VS2017
steps:
- script: echo installing packages
- task: Npm#1
displayName: npm install
inputs:
command: install
- task: Npm#1
displayName: npm test
inputs:
command: custom
customCommand: run test
BTW, you need add #angular/cli dependency in package.json to install angular cli during running npm install command.
Finally got it working, but not 100% satisfied with the solutiuon, posting here the progress and open points plus detailed info to reproduce it, hope it can help other and that we can refine it.
Scenario: I'm in the need of configuring CI on an Angular 4 project and running it under Visual Studio Team Service CI hosted environment, and I want to use the yaml based config.
Issues that I have found:
Hosted enviroment come with old node version (1).
Chrome is not installed by default on the hosted environment, phantom browser is not anymore a solution since it's an abandoned project.
You need to install angular-cli globally.
The current working solution I got, steps:
On your project:
Open your command prompt, install puppeteer, karma-junit-reporter
npm install puppeteer karma-junit-reporter --save-dev
Configure your karma.conf.js
At the top of your file add the following line of code
process.env.CHROME_BIN = require('puppeteer').executablePath();
Then on the pluging sections (add karma-junit-reporter)
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-junit-reporter'), // add karma-unit reporter
require('karma-coverage-istanbul-reporter'),
require('#angular/cli/plugins/karma')
],
On the reporters section set junit reporter as a valid one,and configure it:
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul', 'junit']
: ['progress', 'kjhtml', 'junit'],
junitReporter: {
outputDir: '',
outputFile: 'test.xml',
},
Now it's time to add on the root of your project a file named .vsts-ci.yml (just pasted the raw content in this link: https://pastebin.com/0XpmpPrp)
queue:
name: Hosted VS2017
demands: npm
steps:
- task: NodeTool#0
displayName: "Updating node to version 8.x"
inputs:
versionSpec: "8.x"
task: Npm#1
displayName: "installing angular-cli"
inputs:
command: "custom"
verbose: "false"
customCommand: "install #angular/cli#1.0.2 -g"
task: Npm#1
inputs:
verbose: "false"
task: CmdLine#1
displayName: "run tests: ng test"
inputs:
filename: "ng"
arguments: "test --watch=false --single-run=true --reporters=junit,progress"
task: PublishTestResults#2
displayName: "Publish Test Results (test.xml)"
inputs:
testResultsFiles: "**\test.xml"
testRunTitle: "Jasmine Tests"
What it does:
Update node version.
Globally install angular-cli (I stick to the version that is being used in the package).
Execute a noop command (I don't know why it's needed, but if I don't add this it breaks).
Execute ng test (single run and using junit as reporter).
Publish test results.
Tips and interesting posts I have found:
Use the UI build tool to create the build, then there is an option to convert it to yaml.
Node tool updated task: https://learn.microsoft.com/en-us/vsts/build-release/tasks/tool/node-js
Puppeteer and VSTS: http://benjaminspencer.me/post/14/headless-chrome-vsts
Angular 4 and VSTS (I): https://csharperimage.jeremylikness.com/2016/12/integrating-angular-2-unit-tests-with.html
Angular 4 and VSTS (II): https://blogs.msdn.microsoft.com/premier_developer/2017/05/17/integrating-angular-4-unit-tests-with-visual-studio-team-services-vsts/
Room for improvement:
Avoid having to install angular-cli globally, tried to add a custom script to my package-json, but when I call something like "npm run test:ci" it's not recognized by the visual studio build runner.
I would like to get rid of puppeteer, is karma-jsdom-launcher an option?

Resources