0
0
Jenkinsdevops~30 mins

Build timeouts in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Build timeouts
📖 Scenario: You are managing a Jenkins pipeline that runs automated tests. Sometimes, tests hang and cause the build to run forever. To avoid wasting resources, you want to set a timeout for the build.
🎯 Goal: You will create a Jenkins pipeline script that sets a build timeout of 10 minutes. If the build runs longer, it will be aborted automatically.
📋 What You'll Learn
Create a Jenkins pipeline script with a timeout block
Set the timeout duration to 10 minutes
Inside the timeout block, add a simple echo step
Print a message after the timeout block to confirm the build continues if not timed out
💡 Why This Matters
🌍 Real World
Build timeouts prevent Jenkins builds from running forever, saving resources and avoiding stuck pipelines.
💼 Career
Knowing how to set build timeouts is essential for DevOps engineers to maintain stable and efficient CI/CD pipelines.
Progress0 / 4 steps
1
Create a basic Jenkins pipeline
Create a Jenkins pipeline script with a pipeline block and a stage named 'Test'. Inside the stage, add a single echo step that prints 'Starting tests'.
Jenkins
Need a hint?

Use pipeline and stage blocks. Inside steps, write echo 'Starting tests'.

2
Add a timeout block with 10 minutes duration
Inside the steps block of the 'Test' stage, add a timeout block with time: 10 and unit: 'MINUTES'. Inside the timeout block, add an echo step that prints 'Running tests with timeout'.
Jenkins
Need a hint?

Use timeout(time: 10, unit: 'MINUTES') and put the echo inside its block.

3
Add a step after the timeout block
After the timeout block inside the steps block, add an echo step that prints 'Tests completed or timed out'.
Jenkins
Need a hint?

Simply add echo 'Tests completed or timed out' after the timeout block.

4
Print the final confirmation message
Add a post block to the pipeline with a always section. Inside it, add an echo step that prints 'Build finished' to confirm the pipeline ends regardless of timeout.
Jenkins
Need a hint?

Add a post block with always and inside it echo 'Build finished'.