I have a static web app deployed on an azure app service. This is my gitlab-ci.yml for CI/CD on production -
variables:
API_TOKEN: $DEPLOYMENT_TOKEN
APP_PATH: '$CI_PROJECT_DIR'
REACT_APP_ENV: $REACT_APP_ENV
REACT_APP_GOOGLE_AUTH_CLIENT_ID: $REACT_APP_GOOGLE_AUTH_CLIENT_ID
REACT_APP_OPENAI_API_KEY: $REACT_APP_OPENAI_API_KEY
deploy:
stage: deploy
image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy
script:
- echo "App deployed successfully."
This works great for deploying when I merge to master.
Now I want to update this yml to also do deployments and create preview urls when I open a PR on a branch branched-off master.
How do I update this yml to do that?
Tried -
variables:
API_TOKEN: $DEPLOYMENT_TOKEN
APP_PATH: '$CI_PROJECT_DIR'
REACT_APP_ENV: $REACT_APP_ENV
REACT_APP_GOOGLE_AUTH_CLIENT_ID: $REACT_APP_GOOGLE_AUTH_CLIENT_ID
REACT_APP_OPENAI_API_KEY: $REACT_APP_OPENAI_API_KEY
deploy:
stage: deploy
script:
- apt-get update -qy
- apt-get install -y nodejs npm
- npm install
- npm run build
- curl -sL https://aka.ms/InstallAzureCLIDeb | bash
- az --version
- DEPLOYED_URL=$(az staticwebapp show --resource-group providentiainterviewbackend --name aihyr-prod-frontend --query "defaultHostname" -o tsv)
- echo $DEPLOYED_URL
environment: review/$CI_COMMIT_REF_SLUG
only:
- branches
except:
- master
It says I need to add az login. But wouldnt I need to give credentials for az login? Is there a better and easier way of doing this?
You can utilize GitLab's CI/CD environment variables along with the Azure Static Web Apps CLI to generate preview URLs for branches derived from the master branch, eliminating the need for repeated logins. and use
az loginwith service principal authentication. Make sure TheAZURE_CLIENT_ID,AZURE_CLIENT_SECRET,AZURE_TENANT_ID, andAZURE_SUBSCRIPTION_IDenvironment variables are set in your GitLab CI/CD settings. These values are associated with your Azure service principal.In order to resolve this error:-
Make sure the
Tenant IDvariable you are using if correct and from this option below:-It should be the Tenant Id of the Directory connected to your Azure subscription.
Make sure you are logged into correct directory or Switch to the correct directory that has your subscription which contains the Web app.