0
0
Jenkinsdevops~30 mins

Library versioning in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Library versioning
📖 Scenario: You are managing a Jenkins pipeline that builds a software project. The project depends on a library, and you want to control which version of the library is used during the build.This helps ensure consistent builds and easy updates.
🎯 Goal: Create a Jenkins pipeline script that defines a library version variable, uses it in the build stage, and prints the library version used.
📋 What You'll Learn
Define a variable called libraryVersion with the value 1.2.3
Use the libraryVersion variable in the build stage to simulate using that library version
Print the library version in the pipeline output
💡 Why This Matters
🌍 Real World
Managing library versions in Jenkins pipelines ensures consistent builds and easier troubleshooting.
💼 Career
DevOps engineers often need to control dependency versions in CI/CD pipelines to maintain stable software delivery.
Progress0 / 4 steps
1
Define the library version variable
Create a variable called libraryVersion and set it to the string "1.2.3" at the top of the Jenkins pipeline script.
Jenkins
Need a hint?

Use def libraryVersion = "1.2.3" to define the variable.

2
Add a build stage using the library version
Add a stage named Build that contains a steps block. Inside, add a echo command that prints "Building with library version: ${libraryVersion}".
Jenkins
Need a hint?

Use pipeline { agent any stages { stage('Build') { steps { echo "Building with library version: ${libraryVersion}" } } } }.

3
Add a post section to print the library version after build
Add a post section inside the pipeline block with a always block. Inside always, add a echo command that prints "Library version used: ${libraryVersion}".
Jenkins
Need a hint?

Add post { always { echo "Library version used: ${libraryVersion}" } } inside the pipeline.

4
Run the pipeline and display the output
Run the Jenkins pipeline script and ensure the output contains the lines Building with library version: 1.2.3 and Library version used: 1.2.3.
Jenkins
Need a hint?

Run the pipeline and check the console output for the expected lines.