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:

  • $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

Top comments (4)

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.

Collapse
 
andresparrab profile image
Keny Andres Parra Bobadilla

Hi!
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

Collapse
 
rocke1234e profile image
rock_1234e

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

Collapse
 
karthik1710 profile image
karthik1710

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

Let's team up together 🀝

We're Hiring

We're hiring for a Senior Full Stack Engineer to join the DEV team. Want the deets? Head here to learn more about who we're looking for.