Prerequisites

We can install serverless-azure-functions through the npm. The following command will install the latest version of the plugin, but if you are using the docker image which is created above, it already has the plugin added to it: 

$ npm i --save serverless-azure-functions

But, to interface with the Azure platform, we need to set up Azure subscription credentials locally.  For the serverless-azure-functions plugin to work we need to set up a service principal, which can done through the Azure portal URL as seen in the following:

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal

However,  if you are using PowerShell cmdlets, then use the following:

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authenticate-service-principal 

I will be using CLI for our tutorial , but you are free to use whichever fits best.  or through Azure CLI , Please follow the given steps to get the Azure CLI locally:

https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest

Alternatively, you can use the Azure Cloud Shell, as follows:

https://docs.microsoft.com/en-us/azure/cloud-shell/overview

Once the Azure CLI is successfully installed we should be able to access login by using the following command: 

$ az login

The previous command  will prompt us to visit https://aka.ms/devicelogin and provide us with a code and with Azure identity. We will then be able to access our account through the CLI. We will be provided with account details like the following one on the command line: 

{
"cloudName": "AzureCloud",
"id": "c6e5c9a2-a4dd-4c81b4-6bed04f913ea",
"isDefault": true,
"name": "My Azure Subscription",
"state": "Enabled",
"tenantId": "5bc108159c-4cbe-a7c9-bce05cb065c1",
"user": {
"name": "hello@example.com",
"type": "user"
}
}

We also need to get subscription details through the following command:

$ az account list

Next, we need to create a service principal. We can do this by running the following command. It will provide us with a JSON object that we will need to authenticate with Azure Cloud:  

$ az ad sp create-for-rbac
Retrying role assignment creation: 1/36
{
"appId": "e28115c2-ba87-4ddb-b3fb-62c91ade4a2e",
"displayName": "azure-cli-2018-01-30-01-28-48",
"name": "http://azure-cli-2018-01-30-01-28-48",
"password": "e87a0489-63a7-41a1-b0ef-9054eda5b8c8",
"tenant": "0a76ffdc-0cda-4d93-850f-025f940889dc"
}

And the last pre-requisite we need is for an EnvInject plugin to be installed in Jenkins to mask the Azure credentials. So please make sure that it is added.