0
0
Jenkinsdevops~30 mins

Build history and logs in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Build history and logs
📖 Scenario: You are setting up a Jenkins job to keep track of build history and logs. This helps you see which builds succeeded or failed and review their logs for troubleshooting.
🎯 Goal: Create a Jenkins pipeline script that stores build results and logs in a dictionary, then prints the build history summary.
📋 What You'll Learn
Create a dictionary called build_history with build numbers as keys and their status as values.
Add a variable called latest_build to store the most recent build number.
Use a for loop to collect build logs for each build number in build_history.
Print the build history summary showing build numbers, status, and logs.
💡 Why This Matters
🌍 Real World
Jenkins pipelines keep track of build results and logs to help developers quickly see what happened in each build and troubleshoot failures.
💼 Career
Understanding how to manage build history and logs is essential for DevOps engineers and CI/CD pipeline maintainers to ensure software quality and fast issue resolution.
Progress0 / 4 steps
1
Create initial build history dictionary
Create a dictionary called build_history with these exact entries: 1: 'SUCCESS', 2: 'FAILURE', 3: 'SUCCESS'.
Jenkins
Need a hint?

Use curly braces to create a dictionary with keys 1, 2, 3 and their status values.

2
Add latest build number variable
Add a variable called latest_build and set it to 3.
Jenkins
Need a hint?

Just assign the number 3 to the variable latest_build.

3
Collect build logs in a dictionary
Create an empty dictionary called build_logs. Use a for loop with variable build_num to iterate over build_history.keys(). Inside the loop, add an entry to build_logs with key build_num and value f'Log for build {build_num}'.
Jenkins
Need a hint?

Use a for loop over build_history.keys() and assign formatted strings to build_logs dictionary.

4
Print build history summary
Use a for loop with variables build_num and status to iterate over build_history.items(). Inside the loop, print the line exactly as: Build {build_num}: Status={status}, Log={build_logs[build_num]}.
Jenkins
Need a hint?

Use a for loop over build_history.items() and print the formatted string with build number, status, and log.