Setting up environment variables

Finally, we create environment variables with subscription ID, tenant, name, and password. We need to export this on the Jenkins node and set up a deployment. So let's do that: 

  1. Open the Jenkins in browser and add a new job with a click on New Item. Enter the item name myAzureFunctionDeploy and select Freestyle project, and click OK.
  2. On the job configuration page, tick This project is parameterised and add Password Parameter below the name and default values retrieved from the Azure commands as follows: 
azureServicePrincipalTenantId
azureServicePrincipalClientId
azureServicePrincipalPassword
azureSubId
  1. Let's click on the Source Code Management tab and add the repository URL as https://github.com/shzshi/azure-helloworld-ci.git, the repository has the required files. 
  2. In Build Environment select Inject passwords to the build as environment variables. We are doing this to mask the Azure credentials and other details. 
  3. Next, click on the Build tab and, in the execute shell, add the steps mentioned in the following example, and then click on Save. 
export azureSubId=${azureSubId}
export azureServicePrincipalTenantId=${azureServicePrincipalTenantId}
export azureServicePrincipalClientId=${azureServicePrincipalClientId}
export azureServicePrincipalPassword=${azureServicePrincipalPassword}
serverless deploy
  1. Let's click on Build with parameters. Then click on Build the job will build, create a package and deploy the functions onto the Azure portal. We can test the function on the cloud. Once the function is deployed we can invoke or run through a serverless command prompt. We can integrate this in smoke testing or functional testing, so we test the running of the function in actuality through command line or adding the same line into Jenkins job, as seen in the following:
$ serverless invoke -f hello --data {"name": "DevOps"}

We can also stream the logs of the function, to check how functions got deployed, or how it performed while it ran:

$ serverless logs -f <function_name>

We can change the code in the source code repository and run these commands individually, or through orchestrating tools like Jenkins to perform perfect continuous integration and continuous delivery.

We can integrate removal of the function from the Azure Function through the following command. This can be integrated within the Jenkins pipeline to undeploy or to rollback the function to a previous version:

$ serverless remove