0
0
Jenkinsdevops~30 mins

Hybrid CI/CD approaches in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Hybrid CI/CD Pipeline with Jenkins
📖 Scenario: You work as a DevOps engineer for a small software team. They want to build a simple Jenkins pipeline that combines both Continuous Integration (CI) and Continuous Deployment (CD) steps. This hybrid approach will first build and test the code, then deploy it automatically if tests pass.This project will guide you to create a Jenkinsfile that defines this hybrid CI/CD pipeline in four clear steps.
🎯 Goal: Build a Jenkins pipeline script (Jenkinsfile) that:Defines the source code repositorySets a branch name variable for deploymentRuns build and test stagesDeploys the application if tests succeed
📋 What You'll Learn
Create a pipeline block with agent any
Define a variable branchName with value main
Add Build and Test stages with simple shell commands
Add a Deploy stage that runs only if tests pass
Print a message after deployment
💡 Why This Matters
🌍 Real World
Hybrid CI/CD pipelines are common in real projects to automate building, testing, and deploying software efficiently and safely.
💼 Career
Understanding Jenkins pipelines and hybrid CI/CD approaches is essential for DevOps roles to automate software delivery and improve team productivity.
Progress0 / 4 steps
1
Setup Jenkins pipeline skeleton
Create a Jenkins pipeline script starting with pipeline block and agent any to run on any available agent.
Jenkins
Need a hint?

Start with pipeline { and inside it add agent any to tell Jenkins to run on any agent.

2
Add branch variable for deployment
Inside the pipeline block, add an environment section and define a variable called branchName with the value main.
Jenkins
Need a hint?

Use the environment block to set variables accessible in all stages.

3
Add Build and Test stages
Add a stages block inside the pipeline. Inside it, create two stages: Build and Test. Each stage should run a simple shell command: echo "Building..." for Build and echo "Testing..." for Test.
Jenkins
Need a hint?

Use stage('Name') blocks inside stages. Use steps with sh to run shell commands.

4
Add Deploy stage and print message
Add a third stage called Deploy inside stages. It should run the shell command echo "Deploying branch $branchName". This stage should run only if the previous stages succeed. Finally, add a post block to print Pipeline completed successfully! after all stages.
Jenkins
Need a hint?

Use when with an expression to run Deploy only if previous stages succeeded. Use post { success { ... } } to print a message after the pipeline finishes successfully.