0
0
Jenkinsdevops~20 mins

Why Pipeline as Code matters in Jenkins - See It in Action

Choose your learning style9 modes available
Why Pipeline as Code matters
📖 Scenario: You work in a team that builds software. Your team wants to automate how code is tested and deployed. Instead of clicking buttons in Jenkins every time, you want to write the pipeline steps as code. This way, the pipeline can be saved, shared, and changed easily.
🎯 Goal: You will create a simple Jenkins pipeline script as code. This script will define steps to build and test a project. You will see how writing pipeline as code helps keep automation clear and repeatable.
📋 What You'll Learn
Create a Jenkins pipeline script with a pipeline block
Add an agent section to run the pipeline on any available node
Add a stages section with two stages: Build and Test
In the Build stage, add a step to print Building the project...
In the Test stage, add a step to print Running tests...
💡 Why This Matters
🌍 Real World
Teams use Pipeline as Code to automate software builds and tests reliably without manual clicks.
💼 Career
Knowing how to write Jenkins pipelines as code is a key skill for DevOps engineers and automation specialists.
Progress0 / 4 steps
1
Create the pipeline block
Write a Jenkins pipeline script starting with a pipeline block and an agent any section.
Jenkins
Need a hint?

The pipeline block is the main container. agent any means Jenkins can run this anywhere.

2
Add stages section
Inside the pipeline block, add a stages section with two stages named Build and Test. Leave the stages empty for now.
Jenkins
Need a hint?

The stages section holds all the steps your pipeline will run. Each stage groups related steps.

3
Add steps to stages
Inside the Build stage, add a steps block with a echo step printing Building the project.... Inside the Test stage, add a steps block with a echo step printing Running tests....
Jenkins
Need a hint?

The steps block inside each stage tells Jenkins what to do. echo prints messages to the console.

4
Run and see the output
Run the pipeline script in Jenkins and observe the console output. The output should show Building the project... and Running tests... messages.
Jenkins
Need a hint?

Look at the Jenkins console log after running the pipeline. You should see the messages from both stages.