DEV Community

Alan Castro
Alan Castro

Posted on • Updated on

Gitlab CI script to deploy a Azure Function

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

Variables that I use in the scripts:

  • $FUNCTION_APP your function app's name in azure
  - deploy

  stage: deploy
    - curl -sL | bash
    - apt-get install curl && curl -sL | bash -
    - apt-get install nodejs
    - npm install -g azure-functions-core-tools@3 --unsafe-perm true
    - az login --service-principal -u $APPLICATION_ID -p $APPLICATION_SECRET --tenant $TENANT_ID
    - func azure functionapp publish $FUNCTION_APP --csharp
    - master
Enter fullscreen mode Exit fullscreen mode

Hope it's useful

Discussion (8)

alexsorokoletov profile image
Alex Sorokoletov

Thank you for the setup, it worked like a charm.
I had to figure out how to create service principal correctly but it boiled down to 3 things:

  1. Install Azure CLI and login
  2. Select correct subscription
  3. az ad sp create-for-rbac --name YourPrincipalName

For some reason, YAML formatting goes sideways when you copy the snipped so had to use Gitlab CI lint.

Thanks again, this saved me a lot of time.

derkcrezee profile image
Derk Crezee

Thanks for the info. Might be useful to have a look at the available docker images. The core-tools versions contain the azure cli and azure function core tools.

alandecastros profile image
Alan Castro Author

Thanks! I'll update the article asap

ablob profile image
a blob

Pardon my ignorance, I'm new to all this and have a lot to learn.
With that being said, it looks to me, like you run the curl command and then you try to install curl.
If this is not correct can someone explain what is actually happening here?

arturoaviles profile image
Arturo Avilés • Edited on

Very useful, I have been looking for this ci/cd config file for a long time ago, thanks!

I would recommend to use a Service Principal to Login to Azure to deploy with CI/CD:

alandecastros profile image
Alan Castro Author

Nice! I'll update the post! Thanks!

thbm profile image
Thibault Barolat-Massole

Hi, thank you for sharing.
What permissions should the service principal have?

alandecastros profile image
Alan Castro Author

Sorry for the long delay, but I usually add as a contributor