Next.js Discord

Discord Forum

Jenkinsfile and environment variables

Unanswered
Oriental Scops-Owl posted this in #help-forum
Open in Discord
Oriental Scops-OwlOP
Hi. i have a project where currently i have separate docker and jenkinsfiles for each environment (development/staging, production, and pull request)

i am trying to find out how to downsize this to 1 docker file and 1 jenkinsfile.

im here: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables

i believe i am on next 13 but still using pages folder. the link above suggested getServerSideProps which i want to avoid. I dont understand the second suggestion, "Adopting the app router".

i need to have my Next project set up so whenever i supply env variables after the image is built, the app should still be able to read them at runtime. in my vanilla react apps, i am injecting my env variables into $window and then using that and have had no major issues.

end goal is to have 1 jenkins job set up so it will build an image whenever a PR is submitted . then when I merge a github PR into my master branch, it should trigger a new build with the production environment variables. i can figure this out on my own, just need to figure out the nextjs bit

4 Replies

Oriental Scops-OwlOP
looks like i have to adopt the app folder and app router, and i can access environment variables within server components. this is okay, but i would need to access the env variables outside of server components and within my API fetching class/object
seems like im going to have to stick with the 3 different files, one for each environment unless someone has a better suggestion
i dont think this would work if i wanted to access env variables from outside of pages or app folder