4

I am trying to deploy a simple function in Cloud Builds through a yaml file. This function lives in Github and the Cloud Build trigger point at my repository in order to deploy it. Cloud Build invokes my yaml file without problems but suddenly I get this error

ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: function.js does not exist; Error ID: 7485c5b6

I am not sure why gcloud function deploy is looking for a function.js file when as far as I understand, it just searches for the index.js file. The files that I have are:

  • index.js
  • cloudbuild.yaml
  • package.json
  • package-lock.json

The function deploys successfully through gcloud cli so my bet is that the error exists in the yaml file but it might also be some config in Cloud Build. Here how yaml file looks:

steps:
  - name: "gcr.io/cloud-builders/gcloud"
    args:
      - functions
      - deploy
      - webhook
      - --source=.
      - --trigger-http
      - --runtime=nodejs12
      - --region=europe-west2
      - --allow-unauthenticated

Have somebody any clue of what could be happening? thanks!

2
  • Why is your question tagged with terraform-provider-gcp? Commented Dec 25, 2020 at 7:01
  • because I used terraform to create the infrastructure. it is true I haven't mention it but I thought it wouldn't be relevant for the error. Commented Dec 25, 2020 at 8:57

4 Answers 4

2

The error have been solved installing npm. Adding this to yaml file:

steps:
  - name: "gcr.io/cloud-builders/npm"
    args: ["install"]
    dir: "YOUR_PATH"
Sign up to request clarification or add additional context in comments.

Comments

0

I had the same issue - there's good documentation here - https://cloud.google.com/build/docs/deploying-builds/deploy-functions#yaml

My error was the source as the source flag e.g. if you have a directory structure like.

- test
- deploy
- mint

and you have a cloudbuild.yaml in each directory you have to specify that as the source

steps:
 - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  args:
 - gcloud
 - functions
 - deploy
 - repo-config-test
 - --region=us-central1
 - --source=./test
 - --trigger-http
 - --runtime=nodejs16
 - --entry-point=test
 - --allow-unauthenticated

Comments

0

This happens when you run the deploy statement from a directory other than the directory containing the source. Make sure you are in the root of the directory where your index.js file is when you deploy.

Comments

0

I was getting this error when deploying using GitHub Actions and Terraform. This process requires that you zip the function source then point Terraform to the zip archive.

The problem was that I was using paths in the zip command in the GitHub Action:

zip ./function_directory/build/archive.zip ./function_directory/function.js ./function_directory/package*.json

This recreated the directory structure in the archive - so GCP (rightly) couldn't find the function.js file at the root of the archive.

I changed my GitHub Action to this and it worked:

    - name: Zip Function Source
      run: |
        pushd ./function_directory
        zip ./build/function_source.zip function.js package*.json
        popd

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.