npmazure-devopscypressnpm-installazure-pipelines-tasks

Azure pipeline : Command Line ##[error]Bash exited with code '1'


I am trying to execute my cypress test using azure pipeline but while executing job facing below issue:

yml file:

# To configure triggers for Azure CI see
# https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml#tags
jobs:
  - job: Cypress_tests
    pool:
      vmImage: 'ubuntu-22.04'
    # Runs tests in parallel https://docs.cypress.io/guides/guides/parallelization
    # https://learn.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml
    strategy:
      parallel: 2
    steps:
      - task: NodeTool@0
      # Caches dependencies using npm lock file as key
      # https://docs.cypress.io/guides/continuous-integration/introduction#Caching
      - task: CacheBeta@1
        inputs:
          key: npm | package-lock.json
          path: /home/vsts/.npm
          restoreKeys: npm | package-lock.json
      - task: CacheBeta@1
        inputs:
          key: cy | package-lock.json
          path: /home/vsts/.cache/Cypress
          restoreKeys: cy | package-lock.json
      - script: npm ci --prefer-offline
      # Starts web server for E2E tests - replace with your own server invocation
      # https://docs.cypress.io/guides/continuous-integration/introduction#Boot-your-server
      - script: npm start &
      - script: npx wait-on 'http-get://localhost:3000' # Waits for above
      # Runs tests in parallel and records to Cypress Cloud
      # https://docs.cypress.io/guides/cloud/projects#Set-up-a-project-to-record
      # https://docs.cypress.io/guides/guides/parallelization
      - script: npx cypress run --record --parallel --ci-build-id $BUILD_BUILDNUMBER
        # For recording and parallelization to work you must set your CYPRESS_RECORD_KEY
        # in Azure DevOps → Your Pipeline → Edit → Variables
        env:
          CYPRESS_RECORD_KEY: $(CYPRESS_RECORD_KEY)

Error:

Starting: CmdLine
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.212.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
npm ci --prefer-offline
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/82c8b231-ced2-40c3-9bca-ec69d4282405.sh

Usage: npm <command>

where <command> is one of:
    access, adduser, bin, bugs, c, cache, completion, config,
    ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
    help, help-search, i, init, install, install-test, it, link,
    list, ln, login, logout, ls, outdated, owner, pack, ping,
    prefix, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, tag, team, test, tst, un, uninstall,
    unpublish, unstar, up, update, v, version, view, whoami

npm <cmd> -h     quick help on <cmd>
npm -l           display full usage info
npm help <term>  search for help on <term>
npm help npm     involved overview

Specify configs in the ini-formatted file:

Solution

  • The NodeTool@0 without any parameters sets the active node version to 6, the ci command probably didn't exist back then. Make sure you select a recent version of Node:

    versionSpec - Version Spec

    string. Optional. Use when versionSource = spec. Default value: 6.x.

    Specifies the version spec of the version to get. Examples: 6.x, 4.x, 6.10.0, >=6.10.0.

    - task: NodeTool@0
      inputs:
        versionSpec: "18.x"