Mike H
Mike H

Reputation: 35

Static file referenced by handler not found: build/index.html -Bitbucket Pipeline React App Engine

I have an issue with my Bitbucket CI/CD pipeline. The pipeline itself runs fine, but the application is broken when I try to access it. The pipeline deploys a React App Engine Node.js application. The problem comes when I access the site. This is the error I receive in Google Logging "Static file referenced by handler not found: build/index.html".

If I deploy the application manually, I have no issues and the application works fine. This application error only occurs if the deployment happens in the bitbucket pipeline.

Here is the app.yaml

runtime: nodejs12
handlers:
  # Serve all static files with url ending with a file extension
  - url: /(.*\..+)$
    static_files: build/\1
    upload: build/(.*\..+)$
  # Catch all handler to index.html
  - url: /.*
    static_files: build/index.html
    upload: build/index.html

Here is the bitbucket-pipelines.yml

pipelines:
  branches:
    master:
      - step:
          name:  NPM Install and Build
          image: node:14.15.1
          script:
            - npm install
            - unset CI
            - npm run build
      - step:
          name: Deploy to App Engine
          image: google/cloud-sdk
          script:
            - gcloud config set project $GCLOUD_PROJECT
            - 'echo "$GOOGLE_APPLICATION_CREDENTIALS" > google_application_credentials.json'
            - gcloud auth activate-service-account --key-file google_application_credentials.json
            - gcloud app deploy app.yaml

Any help would be greatly appreciated. Thank you so much.

Upvotes: 0

Views: 757

Answers (1)

Zack
Zack

Reputation: 301

Bitbucket pipelines does not save artifacts between steps. You need to declare an artifacts config in the build step so that you can reference it in the deploy step. Something like this:

pipelines:
  branches:
    master:
      - step:
          name:  NPM Install and Build
          image: node:14.15.1
          script:
            - npm install
            - unset CI
            - npm run build
          artifacts: # Declare artifacts here for later steps
            - build/**
      - step:
          name: Deploy to App Engine
          image: google/cloud-sdk
          script:
            - gcloud config set project $GCLOUD_PROJECT
            - 'echo "$GOOGLE_APPLICATION_CREDENTIALS" > google_application_credentials.json'
            - gcloud auth activate-service-account --key-file google_application_credentials.json
            - gcloud app deploy app.yaml

See here for more details: https://support.atlassian.com/bitbucket-cloud/docs/use-artifacts-in-steps/

Note that I have not tested this.

Upvotes: 1

Related Questions