DEV Community

Alan Castro
Alan Castro

Posted on

Gitlab CI script to deploy a .NET core Azure Webapp

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:

  - deploy

  stage: deploy
    - apt-get update && apt-get -y install zip
    - curl -sL | bash
    -  az login --service-principal -u $AZ_SERVICE_PRINCIPAL_URL -p $AZ_SERVICE_PRINCIPAL_SECRET --tenant
    - dotnet restore --configfile ./NuGet.config 
    - dotnet publish -c release -o out
    - cd out && zip -r .
    - az webapp deployment source config-zip -n $AZ_APP_NAME -g $AZ_APP_RESOURCE_GROUP --src
    - master

Hope it's useful

Top comments (4)

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.

andresparrab profile image
Keny Andres Parra Bobadilla

Thanks for this info, it help me understand better.
But i was wondering if you could help me with this task:
I want to deploy to azure let say a solution with both webjobs, webapp, etc to azure everything is in .Net exept the front end that is in Angular.
And i want to have a pipeline that look lite this:
build, test (unit, integration)-> deploy to DEV -> Deploy to Qa -> Deply to Staging -> swap to production.

I want to have this kind of pipeline so that i cant test my donet app in dev, end if every is working send it to acc and so on and so on.

I have look in google, youtube etc. but it seem dificult to find this info for .net with gitlab.

In azure devops you can choose like build for .net and will get lot of predifine task, like restore the solutionm download nugets, build the solution and zip in in an artifac. also for deply to different stages. But with gitlab i dont fins such things.
Sorry for the lon text.

Thank you in advance. anoob in gitlab

rocke1234e profile image

Dude thank you so much I was struggling to make a deployment to an app service.

karthik1710 profile image

Im new to Azure. Is there any blog post to create service-principal logins for webapp. Thanks