I'm trying to deploy a NestJS backend app from Bitbucket Pipelines to Heroku using the atlassian/heroku-deploy pipe.
What I Have:
My repo is hosted on Bitbucket.
project
/backend
/frontend
.bitbucket-pipelines.yml
image: node:18
pipelines:
branches:
dev:
- step:
name: Build App - (Dev)
script:
- cd backend
- npm install
- npm run build
- step:
name: Create Artifact (Dev)
script:
- cd backend
- git archive --format=tar.gz dev -o application.tar.gz
artifacts:
- backend/application.tar.gz
- step:
name: Deploy to Heroku (Dev)
deployment: Staging
script:
- pipe: atlassian/heroku-deploy:2.4.1
variables:
HEROKU_API_KEY: $HEROKU_API_KEY
HEROKU_APP_NAME: $HEROKU_APP_NAME
ZIP_FILE: backend/application.tar.gz
WAIT: "true"
caches:
- node
i have no proc file but in my backend/package.json?
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "node dist/main",
Bitbucket Repository Variables:
HEROKU_APP_NAME is set to the correct app (devcrm)
HEROKU_API_KEY is copied from Heroku dashboard > Account > API Key (no extra spaces/quotes)
API Key Works:
I tested the API key in Postman and confirmed it successfully returns my apps with:
GET https://api.heroku.com/apps
Authorization: Bearer <api-key>
Accept: application/vnd.heroku+json; version=3
The Issue:
Despite all that, the deployment fails in the pipeline with this error:
✖ Failed to create sources. Expected HTTP Status 201, got 401.
Error message: {"id":"unauthorized","message":"Invalid credentials provided."}
What I've Tried:
Regenerated and re-added the API key
Confirmed environment variables are visible in the pipeline
Tried using older and newer versions of the atlassian/heroku-deploy pipe
Ensured my Heroku account matches the app ownership