Access to DATABASE_URL during build time in the App Platform

I was looking at the environment variables for an App I created in the App Platform with a PostgreSQL database and that the DATABASE_URL is available during build time:

Your component will have access to these variables at both build time and runtime.

However, when trying to access it during the build it wasn’t available. I also downloaded the YAML spec for the app where the scope was set to RUN_TIME

Is there a way to configure DATABASE_URL to be available during build time via the UI?

The only way I can think of doing this is downloading the spec, updating the scope, and then updating the app with the doctl.

Besides that, could the availability of the DATABASE_URL env var be better clarified in the UI to avoid confusion?

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

👋 @danielnorman

Currently there is not a way for DATABASE_URL (or any other database bind variables) to be available during build.

We plan on supporting build time access to databases soon though we don’t have a specific timeline just yet.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@jameshfisher, I landed on this thread looking for an answer to this too. For me specifically I was looking to run some database migrations, and I couldn’t get at the DATABASE_URL environment variable at build time.

On this documentation page (

They explain:

Database values are not available during build time but are available at runtime.

So that just isn’t an option, and based on other feedback I’ve read it won’t be an option.

But have hope, you should be able to utilize “Jobs” to achieve the desired effect you’re looking for.

The documentation to set a job up can be found at (

One thing that tripped me up when I was creating the job, was that after you link the particular repo, and hit "Next", I think it autodetects the type of resource you want to create based on the project (in my case it autodetected my repo as a "Web Service"). So you’ll have to edit that resource and change the "Resource Type" to "Job".

After choosing "Job" you have the option of choosing when the job gets run:

  • After every failed deploy
  • After every successful deploy
  • Before every deploy

In your case “Before every deploy” to build those pages prior to deployment is probably what you want. Don’t forget to add the DATABASE_URL environment variable for that job as well.

Hope this helps!

There is no workaround for this. Even if you set DATABASE_URL manually, any attempt to connect to it at build time results in a connection timeout.