Access env_variables from app.yaml in Cloud Build

I found a lot of questions about pass environment variables from Google Cloud Build to App Engine, but my case is a bit different.

I have a website in NextJS deployed in GAE, but i used the Gitlab CI to deploy to GAE not the Cloud Build. The problem is NextJS needs the envirmonte variables in build time (that occurs in Cloud Build) and the variables defined in app.yaml arent setted when the build occurs.

To fix this i followed this answer https://stackoverflow.com/a/55581164 and created a sh file that generates the .env on Gitlab before deploy to GAE.

My question is: is there a better way to access variables in Cloud Build since they are already present in app.yaml? Is this the default behavior or is it a bug?

My .gitlab-ci.yml:

image: rlancer/gcloud-node:1.0.2

deploy_production:
  stage: deploy
  environment: Production
  only:
  - master
  before_script:
    - chmod +x ./setup_env.sh
    - ./setup_env.sh
  script:
  - npx gae-ayaml-env # generates the app.yaml putting the env_variables from gitlab
  - echo $SERVICE_ACCOUNT > /tmp/$CI_PIPELINE_ID.json
  - gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json
  - gcloud --quiet --project $PROJECT_ID app deploy app.yaml dispatch.yaml

after_script:
- rm /tmp/$CI_PIPELINE_ID.json

My app.yaml generated by npx gae-ayaml-env:

runtime: nodejs12

handlers:
- url: /.*
  script: auto
  secure: always
  redirect_http_response_code: 301
env_variables:
  NEXT_PUBLIC_API_URL: https://example.com