loading...

Gitlab CI script to deploy a .NET core Azure Webapp

alandecastros profile image Alan Castro ・1 min read

Here is the .gitlab-ci.yml that I use to deploy my .NET Core 3.1 azure web app in Gitlab CI/CD.

Variables that I use in the scripts:

  • $AZ_SERVICE_PRINCIPAL_URL
  • $AZ_SERVICE_PRINCIPAL_SECRET
  • $AZ_SERVICE_PRINCIPAL_TENANT
  • $AZ_APP_NAME
  • $AZ_APP_RESOURCE_GROUP
stages:
  - deploy

deploy:
  stage: deploy
  image: mcr.microsoft.com/dotnet/core/sdk:3.1
  script:
    - apt-get update && apt-get -y install zip
    - curl -sL https://aka.ms/InstallAzureCLIDeb | bash
    -  az login --service-principal -u $AZ_SERVICE_PRINCIPAL_URL -p $AZ_SERVICE_PRINCIPAL_SECRET --tenant
        $AZ_SERVICE_PRINCIPAL_TENANT
    - dotnet restore --configfile ./NuGet.config 
    - dotnet publish -c release -o out
    - cd out && zip -r app.zip .
    - az webapp deployment source config-zip -n $AZ_APP_NAME -g $AZ_APP_RESOURCE_GROUP --src app.zip
  only:
    - master

Hope it's useful

Discussion

pic
Editor guide
Collapse
mvacha profile image
Michal Vácha

Thank you for your article - it was exactly what I was looking for 👍. I found this aproach (zip deployment and run from package) much better than using a "Local Git" repo as recommanded in the offical docs and all other articles I've found.