# Cloud Build: ERROR: build step 2 "gcr.io/cloud-builders/npm" failed: step exited with non-zero status: 1

**Code:** `Cloud Build: step exited with non-zero status` · **Category:** Google Cloud / Firebase · **Seen on:** Google Cloud

One step of the Cloud Build pipeline returned a non-zero exit code, so the whole build failed.

## Meaning

Open the build log and read the output of that step (the failing command is printed above). Reproduce locally in the same builder image or with `cloud-build-local`. Typical issues: failing tests, missing files because of `.gcloudignore`, wrong working directory (`dir:`), or lack of permissions for deploy steps.

## Common causes

- Tests/build commands failing in the step
- Files excluded by .gcloudignore/.gitignore
- Wrong `dir` or `entrypoint`
- Cloud Build service account lacking a role (deploy, push)
- Missing substitution variables

## Quick fix

1. Read the failing step's log output
2. Run locally with `cloud-build-local --config=cloudbuild.yaml .`
3. Add required roles to the Cloud Build service account

## Detailed fix by platform

### gcloud

1. `gcloud builds log BUILD_ID` and `gcloud builds describe BUILD_ID --format="value(status,failureInfo)"`

## Code examples

### cloudbuild.yaml step

```yaml
steps:
  - name: 'gcr.io/cloud-builders/npm'
    args: ['ci']
  - name: 'gcr.io/cloud-builders/npm'
    args: ['test']
```

## How to diagnose

1. **Step** — Which number?
2. **Log** — First error?
3. **Rights** — Build SA roles?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/gcp/cloudbuild-step-failed-non-zero)
