Continuous delivery pipeline to OpenWhisk

Continuous delivery is one of the essential features of DevOps. It not only helps in facilitating quicker deployment to production, but it also helps to create a bug-free application. We will be using Jenkins, Serverless Framework, and features of the OpenWhisk cloud to build a continuous delivery platform for OpenWhisk functions. We will be picking up the same weather system app that we built earlier with the freestyle job and enhance it to conform to the continuous delivery model. I have added the required files to the Git repository that I mentioned earlier in the chapter. By using Jenkinsfile at the root, we define a multistage pipeline for this project. Jenkinsfile is a groovy script that is used by Jenkins to run pipelines. We will use master branch to code for deploying and testing to various environments from the development stage all the way to production, provided that the deployment and tests passes within the pipeline. Integration tests run after each deployment (except production) and validate whether the deployed stack is functioning as expected. The pipeline we are creating here will be using Jenkinsfile and Serverless Framework, creating multiple Cloud Foundry spaces for different environments, unit- testing sessions, and building promotions. Let's start with Cloud Foundry spaces by going through the following steps:

  1. Log into Bluemix at https://bluemix.net.
  2. Navigate to Manage | Account | Cloud Foundry Orgs.
  3. Click on the View details link and then on the link to add Cloud Foundry space. A popup should open.
  4. Add four environments: development, SIT, preproduction, and production.

Once the space is created, we will create API keys for the environment and push them as parameters in Jenkins to use them for deploying to different environments: 

  1. Click on Three Line on the left-hand side of the Bluemix portal.
  2. Then go to Functions and click on it, and then click on the API Key link.
  3. We will copy the host and key for all environments. We can change and move to the environment from the CLOUD FOUNDRY SPACE dropdown, as shown in the following screenshot:

Now we will move to Jenkins, where we will create a pipeline job. I have added the Jenkinsfile to the Git repository at https://github.com/shzshi/OpenWhisk-weather-report-serverless/blob/master/Jenkinsfile, where we will use the same Git to set up the pipeline.

We will use the same Jenkins Docker container that we created earlier in the previous tutorials. We will create a new job and work on it. Go through the following steps:

  1. Open Jenkins in the browser at http://localhost:8080
  2. Log into Jenkins and create a New item
  3. Enter the item name as OpenWhisk_serverless_pipeline, select Pipeline, and click OK.
  4. We will be redirected to another page, where we need to parameterize the pipeline with OpenWhisk auth, OpenWhisk host, and a Git path for the pipeline. For this, we will tick the This project is parameterised checkbox.
  5. Then, in the Add Parameter dropdown, we need to select Credentials Parameter as the parameter for the pipeline. The following screenshot shows the page for adding details into the credentials parameter. We have to add credentials parameters for all the environments that we created earlier in the chapter through the Azure portal. The Credential type should be Secret text, because this will help us to keep the authentication keys hidden, as they are passed as environment variables within the Jenkins pipeline. So, in total, we will create five credentials parameters: four for the different environments that are in development, SIT, preproduction, and production, and then the fifth for the OpenWhisk host. The secret text values should be populated from the Bluemix portal in the API Key section. The Default Value should be filled by clicking the Add button and then selecting Jenkins, which will help us to add auth keys into the Jenkins credentials provider. Look at the following screenshot for more information:
  1. We will set the credentials as Secret text. Then the Secret text box will be filled with the API Key for each environment, which we can get from the Azure portal. Then the ID and Description fields would each be given a simple name, such as OpenWhisk_DEV_AUTH, as references, as shown in the following screenshot:
  1. Once all the parameters for each environment are added, we need to move to the Pipeline tab and add the GitHub path. The following screenshot shows us adding the configuration for the Jenkins pipeline:
  1. Once everything is set, then we need to run the job with the parameters. Once the job runs successfully, as shown in the following screenshot, Serverless Framework will package the functions files and they will be deployed on the different environments that we are testing through the serverless invoke: