DEPLOY-WEBAPPS-TO-AZURE-APP-SERVICE-USING-JENKINS

Kaan Turgut
5 min readFeb 15, 2023

--

  • Welcome to this comprehensive guide on deploying five web applications to Azure App Service using Jenkins. This Readme provides detailed instructions on the process, ensuring seamless and efficient deployment for all five applications.

Even each app does not have a Readme , the steps outlined here apply uniformly to all of them.

https://github.com/hkaanturgut/DEPLOY-CONTAINERIZED-WEBAPPS-TO-AZURE-APP-SERVICE-USING-JENKINS.git

Let’s get started!

APPS :

  • Tetris-Game-App
  • Apprun-realworld-example-app
  • Crizmas-mvc-realworld-example-app
  • React-redux-realworld-example-app

Prerequisites :

Project Task and Steps:

1- Create a Azure Container Registry >>> ACR Terraspace Codes

2- Provision a Jenkins Server , can use dind ( docker in docker container which contains Jenkins ) >> ACR Terraspace Codes

  • You know what to do ! Go ahead and set up your Jenkins

3- Once the Jenkins is all set up , install the needed plugins ( Azure app Service )

  • From Dashboard > Manage Jenkins > Manage Plugins > Available Plugins
  • Once select the plugins , select install without restart

4- Credentials need to be added in order to have connection with ACR and our Azure account

  • From Dashboard > Manage Jenkins > Credentials > System > Global credentials > Add credentials
  • Add the selected container registry credentials , in this project it is ACR.
  • In order to have connection with our Azure account , I created service principal and made the connection with Jenkins

Here are the needed credentials to be able to keep going for the further steps

5- Let’s create the pipeline.

6- Starting our pipeline firstly by checking our code from the repository

- pipeline{
agent any
stages{
stage('git checkout'){
steps{
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/hkaanturgut/Tetris-App-Jenkins.git']])
}
}
}
}
  • Click Build Now and here is the succesfull step

7- Build Docker image and push it to the ACR

- stage('build docker image'){
steps{
sh 'docker build -t jenkinsacrkaan.azurecr.io/tetris .'
}
}
stage('push image'){
steps{
withCredentials([usernamePassword(credentialsId: 'ACR', passwordVariable: 'password', usernameVariable: 'username')]) {
sh 'docker login -u ${username} -p ${password} jenkinsacrkaan.azurecr.io'
sh 'docker push jenkinsacrkaan.azurecr.io/tetris'
}
}
}
  • Click Build Now and the image is build and pushed to the ACR

8- Install Azure CLI into the pipeline

- stage('install Azure CLI'){
steps{
sh '''
apk add py3-pip
apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
pip install --upgrade pip
pip install azure-cli
'''
}
}
  • Click Build Now and Azure CLI is installed into the pipeline

RELEASE TO AZURE WEB APPS

Deploy to Web App

- stage('deploy web app'){
steps{
withCredentials([azureServicePrincipal('azureServicePrincipal')]) {
sh 'az login --service-principal -u ${AZURE_CLIENT_ID} -p ${AZURE_CLIENT_SECRET} --tenant ${AZURE_TENANT_ID}'
}
withCredentials([usernamePassword(credentialsId: 'ACR', passwordVariable: 'password', usernameVariable: 'username')]) {
sh 'az webapp config container set --name tetris-game-webapp --resource-group Tetris-App-RG --docker-custom-image-name jenkinsacrkaan.azurecr.io/tetris:latest --docker-registry-server-url https://jenkinsacrkaan.azurecr.io --docker-registry-server-user ${username} --docker-registry-server-password ${password}'
}
}
}
  • Click Build Now and App deployed to Azure App Service

Make sure to add WEBSITES_PORT setting from ;

- Configuration > Application Settings > Add WEBSITES_PORT ( add your app's port ) > Sav

APP IS WORKING

Thank you for taking the time to read this blog.I hope that the information provided here proves to be useful in your efforts to efficiently deploy your applications. Best of luck.

--

--

No responses yet