0
0
Jenkinsdevops~30 mins

Implicit vs explicit loading in Jenkins - Hands-On Comparison

Choose your learning style9 modes available
Implicit vs Explicit Loading in Jenkins Pipeline
📖 Scenario: You are working on a Jenkins pipeline for a software project. You want to understand how to load shared libraries in Jenkins pipelines using implicit and explicit methods.
🎯 Goal: Build a Jenkins pipeline script that demonstrates both implicit and explicit loading of a shared library.
📋 What You'll Learn
Create a Jenkins pipeline script with a pipeline block
Use implicit loading of a shared library named utils
Use explicit loading of the same shared library utils
Call a function sayHello from the shared library in both cases
Print the outputs of the function calls
💡 Why This Matters
🌍 Real World
Jenkins shared libraries help reuse common pipeline code across many projects, improving maintainability and consistency.
💼 Career
Understanding implicit and explicit loading of shared libraries is essential for Jenkins pipeline developers and DevOps engineers to write modular and scalable pipelines.
Progress0 / 4 steps
1
Create a Jenkins pipeline with implicit library loading
Create a Jenkins pipeline script with a pipeline block. Use the @Library('utils') annotation to implicitly load the shared library named utils. Inside the stages, add a stage named Implicit Load that calls the function sayHello() from the library and stores the result in a variable called implicitResult.
Jenkins
Need a hint?

Use @Library('utils') annotation at the top and call sayHello() inside a script block.

2
Add explicit loading of the shared library
Add a variable called utilsLib that explicitly loads the shared library utils using the library step. Call the sayHello() function inside a new stage named Explicit Load and store the result in a variable called explicitResult.
Jenkins
Need a hint?

Use def utilsLib = library('utils') to explicitly load the library, then call sayHello() on the loaded library object.

3
Combine implicit and explicit results
Inside the script block of the Explicit Load stage, create a new variable called combinedResult that concatenates env.implicitResult and explicitResult separated by a comma and a space.
Jenkins
Need a hint?

Use string concatenation with env.implicitResult + ", " + explicitResult to combine the two variables.

4
Print the combined result
Add a println statement inside the Explicit Load stage's script block to print the combinedResult variable.
Jenkins
Need a hint?

Use println(combinedResult) to display the combined message.