Serverless Package Stage Agnostic Assistance

Hello! In regards to serverless package I am looking to create a CI pipeline that only builds once and leverages the artifact (json and zip) generated by serverless to deploy to each environment. My assumption was that the deployable would be environment agnostic. In my serverless.yaml I’ve defined out my stage entry as stage: ${env:STAGE} but after some digging I realized that by default serverless package defaults stage to dev so my serverless-state.json is outputting “stage”: “dev”

My dev stage is deploying correctly, but once I want to promote that same deployable it’s failing obviously. Is there something I’m doing wrong or incorrectly thinking about regarding serverless deployments? The only thing I’m opposed to currently regarding solution is just building and deploying in the same job.

Any help would be greatly appreciated! Thanks!

What does your serverless.yml look like?

You can set the stage key under the provider block

@DavidWells

Thanks for your prompt reply!

I went ahead and created a minimal reproducible repo for you to see a working example.

My misunderstanding is just regarding the sls package command and why it defaults to dev even though I defined in the yml an environmental variable in the stage entry. My hope was that a environment agnostic package could be created and either opt or env variables could be leveraged to finalize the deploy like so:

sls deploy --stage production --package /path/to/package

Let me know if you need anything else!

Since this discussion a week (or so) ago I just made sls deploy handle both build and deploy of the artifacts. The issue I was running into seems… incorrect. I’ll await further clarification before removing my inquiry.

@dmhalejr did you ever find a way to create environment-agnostic builds? I’m still wading through the docs and articles but haven’t found a way yet.

There’s an open bug for it: Allow to create reusable cross-stage deployment ready build artifacts · Issue #3528 · serverless/serverless · GitHub

Hey @mmaglana,

Thanks for checking out! Sadly I never found a way around this error and believe I still have my minimal viable project available.

I may take a stab this weekend in getting it up-to-date and checking with the latest version of serverless:

What does your serverless.yml look like?
Speed Test