You are on page 1of 4

Lab Manual: Creating a CD Pipeline in Jenkins and Deploying to Azure

Cloud

Objective:
The objective of this lab is to guide you through the process of setting up a
Continuous Delivery (CD) pipeline using Jenkins to automate the deployment
of a sample application to the Azure cloud platform.

Prerequisites:
• Jenkins installed and accessible (Refer to the "Installing Jenkins on
Azure Cloud" lab manual)
• Sample application source code hosted in a version control system (e.g.,
GitHub)
• Azure account with necessary permissions to create and manage
resources
• Basic understanding of Jenkins, version control systems, and Azure
services

Lab Steps:

1. Access Jenkins Dashboard:


• Open a web browser and navigate to your Jenkins instance (e.g.,
http://<your-vm-public-ip>:8080).
• Log in with your Jenkins admin credentials.

2. Install Required Plugins:


• Navigate to Manage Jenkins > Manage Plugins > Available.
• Search for and install the following plugins if not already installed:
• Azure Credentials Plugin
• Azure App Service Plugin
• Pipeline Plugin
• Git Plugin

3. Configure Azure Credentials:


• Navigate to Manage Jenkins > Manage Credentials > (Global)
• Click Add Credentials and select Microsoft Azure Service Principal.
• Enter your Azure Service Principal details (Client ID, Client Secret,
Subscription ID, and Tenant ID) and give it an appropriate ID (e.g.,
azure-credentials).
• Click OK to save the credentials.

4. Create a New Jenkins Pipeline:


• Navigate to New Item from the Jenkins dashboard.
• Enter a name for your pipeline (e.g., "SampleApp_CD_Pipeline").
• Choose Pipeline as the project type and click OK.

5. Configure Pipeline:
• In the pipeline configuration page:
• Under General, define your pipeline description.
• Under Pipeline, select Pipeline script from SCM as the
Definition.
• Choose your version control system (e.g., Git) and provide the
repository URL.
• Specify the branch to build (e.g., main or master).
• Save your configuration.

6. Create Jenkinsfile:
• In your source code repository, create a Jenkinsfile at the root level.
• Define your pipeline stages and steps in the Jenkinsfile. Include stages
for build, test, and deploy. For example:
groovyCopy code

pipeline {

agent any

stages {

stage('Checkout') {

steps {

git branch: 'main', url: 'https://github.com/your-


username/sample-app.git'

stage('Build') {

steps {

sh 'mvn clean package'

stage('Test') {

steps {

sh 'mvn test'

stage('Deploy to Azure App Service') {

steps {
azureWebAppPublish appName: 'your-app-name',

resourceGroup: 'your-resource-group',

filePath: 'target/*.war'

post {

always {

// Clean up or notify

success {

// Notify success

failure {

// Notify failure

7. Save and Run Pipeline:


• Once your Jenkinsfile is configured, save it in your repository.
• Go back to your Jenkins dashboard and navigate to your pipeline.
• Click on Build Now to trigger the pipeline execution.

8. Monitor Pipeline Execution:


• Monitor the progress of your pipeline on the Jenkins dashboard.
• Click on the build number to view detailed logs of each stage.
• Troubleshoot any issues encountered during the build, test, or
deployment process.

9. Verify Deployment:
• Once the pipeline execution is complete, verify that your application is
deployed to the Azure App Service.
• Access your deployed application using the Azure App Service URL.
10. Post-Deployment Actions (Optional):
• Optionally, configure post-deployment actions such as setting up
custom domain, configuring SSL, or integrating with Azure monitoring
services.

Conclusion:
In this lab, successfully created a Continuous Delivery (CD) pipeline using
Jenkins to automate the deployment of a sample application to the Azure
cloud platform. By integrating Jenkins with Azure services, you can establish
a robust CD workflow that streamlines the deployment process and enhances
the efficiency of your software delivery pipeline.

You might also like