0
0
Jenkinsdevops~30 mins

Blue-green deployment pattern in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Blue-green deployment pattern
📖 Scenario: You work as a DevOps engineer managing a web application deployment. To avoid downtime during updates, you want to use the blue-green deployment pattern. This means you have two identical environments: blue and green. Only one environment serves live traffic at a time. When deploying a new version, you update the inactive environment, then switch traffic to it.
🎯 Goal: Build a Jenkins pipeline script that defines two environments blue and green, sets the active environment, deploys the new version to the inactive environment, and switches traffic to it.
📋 What You'll Learn
Create a variable environments with values ['blue', 'green']
Create a variable activeEnv set to 'blue'
Write a function getInactiveEnv that returns the environment not currently active
Print the inactive environment, deploy to it, then switch activeEnv to it
Print the new active environment after switching
💡 Why This Matters
🌍 Real World
Blue-green deployment is used in real companies to update applications without downtime by switching traffic between two identical environments.
💼 Career
Understanding this pattern helps DevOps engineers automate safe deployments and reduce risks during updates.
Progress0 / 4 steps
1
Define environments list
Create a variable called environments and set it to the list ['blue', 'green'].
Jenkins
Need a hint?

Use square brackets to create a list with two strings: 'blue' and 'green'.

2
Set active environment
Create a variable called activeEnv and set it to the string 'blue'.
Jenkins
Need a hint?

Assign the string 'blue' to the variable activeEnv.

3
Create function to get inactive environment
Write a function called getInactiveEnv that returns the environment from environments that is not equal to activeEnv. Use a for loop with variable env to check each environment.
Jenkins
Need a hint?

Loop over environments and return the one not equal to activeEnv.

4
Deploy to inactive environment and switch active environment
Call getInactiveEnv() and store the result in inactiveEnv. Print "Deploying to {inactiveEnv} environment". Then set activeEnv to inactiveEnv. Finally, print "Switched active environment to {activeEnv}".
Jenkins
Need a hint?

Use print statements with string formatting to show deployment and switching messages.