BitBucket Firebase Pipeline error
Asked by RobT:

I'm getting a strange error when I get to the deploy step of firebase.

The config (*/bitbucket-pipeline.yaml*) steps look like this...  

```
image: node:16

pipelines:
  branches:
    dev:
      - step:
        name: Setup
        caches:
          - node
        script:
          - npm install
      - step:
        name: Build
        caches:
          - node
        script:
          - npm run build:dev
        artifacts:
          - build/**
      - step:
        name: Deploy
        caches:
          - node
        deployment: staging
        script:
          - pipe: atlassian/firebase-deploy:1.3.0
            variables:
              PROJECT_ID: $FIREBASE_PROJECT_ID
              KEY_FILE: $FIREBASE_PRIVATE_KEY
              DEBUG: "true"
```

The (*/package.json*) file looks something like this (hopefully this is all the relevant parts)...

```
{
  ...
  "engines": {
    "node": 16
  },
  ...
  "dependencies": {
    ...
    "firebase": "^9.6.1",
    ...
    "react-scripts": "5.0.0",
    ...
  },
  "scripts": {
    ...
    "build:dev": "env-cmd -f .env.development react-scripts build",
    ...
  }
}
```

The deployment error looks like this...

    Status: Downloaded newer image for bitbucketpipelines/firebase-deploy:1.3.0
    DEBUG: Starting new HTTPS connection (1): http://bitbucket.org/
    DEBUG: https://bitbucket.org/ "GET /bitbucketpipelines/official-pipes/raw/master/pipes.prod.json HTTP/1.1" 200 None
    INFO: Executing the pipe...
    INFO: Current NodeJS version:
      installing : node-v12.22.12
           mkdir : /usr/local/n/versions/node/12.22.12
           fetch : https://nodejs.org/dist/v12.22.12/node-v12.22.12-linux-x64.tar.gz
       installed : v12.22.12 (with npm 6.14.16)
    Traceback (most recent call last):
      File "/main.py", line 170, in <module>
        pipe.run()
      File "/main.py", line 108, in run
        key_content = base64.b64decode(key_file)
      File "/usr/local/lib/python3.7/base64.py", line 87, in b64decode
        return binascii.a2b_base64(s)
    binascii.Error: Incorrect padding

I can't see anything out of the ordinary. Could anyone please point me at what might be wrong?


Answers:
author: o_kyrdan
body: Hi [@RobT](/t5/user/viewprofilepage/user-id/4862780)

Looks like the KEY_FILE encoding error.

The KEY_FILE should be base64 encoded content of Key file for a [Google service account](https://cloud.google.com/iam/docs/creating-managing-service-account-keys). To encode this content, follow [encode private key docs](https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/#Use-multiple-SSH-keys-in-your-pipeline).

Linux

```
$ base64 -w 0 < my_gcp_key
```

Mac OS X

```
$ base64 < my_gcp_key
```

More details about [firebase-deploy](https://bitbucket.org/atlassian/firebase-deploy/) pipe you could find in the [Readme](https://bitbucket.org/atlassian/firebase-deploy/src/master/README.md).

Best regards,  
Oleksandr Kyrdan

comments: author: RobT
body: Thank you [@o_kyrdan](/t5/user/viewprofilepage/user-id/2862136) , that was exactly it. I missed the base64 part. Silly mistake.


Tags: bitbucket-cloud

bitbucket-pipelines

deployment

firebase

google