I was trying to setup a deployment for an SPA application to an Azure Static Web app using TeamCity, but most of the tutorials I found was doing the deployment through CI/CD of Github’s Actions by monitoring a specific branch of a Github repository and deploy automatically whenever we check in into that branch, or the other alternative is using Azure DevOps pipeline. But what if we don’t want to use neither, and instead we need to do it on demand from TeamCity, or any other CI/CD tool?
I found a tool created by Microsoft which provides cli support to manage and deploy to static website.
The tool called Azure Static web app CLI.
The tool provides more than deployment functionality, but has lots of features to emulate authentication, and provide proxy for the API calls from the static web site.
But in this post we will only talk about the deployment using that tool:
- install the tool using npm
1npm install -g @azure/static-web-apps-cli
- login using the command to login to your azure subscription and connect to existing static web app.
If you don’t have an app yet, then just ignore the
app-nameargument, and the tool will create a new app for you.
1swa login --subscription-id <subscription> --resource-group <group name> --app-name <the app-name>
navigate to the folder that has the production static files, for example let’s assume our deployment files are in folder
if you want to deploy to a new static web app, then just do:
1swa deploy ./dist
This will ask you about the name of the new app, and will create it.
In case you want to deploy to an existing static web app, then first you need to get that application token by doing this
1az staticwebapp secrets list --name <the name of your app> --query "properties"
This will display a json as follows:
2 "apiKey": "cf........700f62213"
the apikey is the token.
Then run the following:
1swa deploy ./dist --deployment-token <the token>
You will get confirmation as follows:
This will not deploy to production, but to a preview environment.
So the URL will be the same URL of your static web app, but tailed with “preview”.
This feature will give you a chance to check your app, before going to production.
To deploy to production you add
--env production to the previous command , so it will be
1swa deploy ./dist --deployment-token <token> --env production