0
0
Jenkinsdevops~30 mins

Global shared library configuration in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Global Shared Library Configuration in Jenkins
📖 Scenario: You work in a team that uses Jenkins for automation. To reuse common pipeline code, your team wants to set up a global shared library in Jenkins. This library will hold reusable scripts and steps for all Jenkins pipelines.
🎯 Goal: Learn how to configure a global shared library in Jenkins by defining its name, repository, and default version. Then, use it in a simple Jenkins pipeline.
📋 What You'll Learn
Create a global shared library configuration dictionary with exact keys and values
Add a configuration variable for the default branch of the library
Write the Jenkins pipeline code that uses the shared library
Print the pipeline script output to verify the library usage
💡 Why This Matters
🌍 Real World
Teams use global shared libraries in Jenkins to reuse common pipeline code, reducing duplication and errors.
💼 Career
Knowing how to configure and use shared libraries is essential for Jenkins pipeline developers and DevOps engineers to build scalable automation.
Progress0 / 4 steps
1
Create the global shared library configuration dictionary
Create a dictionary called global_shared_library with these exact entries: name set to "my-shared-lib", repository set to "https://github.com/example/my-shared-lib.git", and default_version set to "master".
Jenkins
Need a hint?

Use curly braces {} to create a dictionary. Use exact keys and values as strings.

2
Add a configuration variable for the default branch
Add a variable called default_branch and set it to the string "main" to represent the default branch of the shared library.
Jenkins
Need a hint?

Use a simple assignment statement to create the variable default_branch.

3
Write the Jenkins pipeline code that uses the shared library
Write a string variable called pipeline_script that contains this exact Jenkins pipeline code using the shared library my-shared-lib with the default branch main:
"""
library('my-shared-lib@main')
pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                echo 'Using shared library'
            }
        }
    }
}
"""
Jenkins
Need a hint?

Use triple quotes """ to create a multi-line string. Include the exact pipeline code inside.

4
Print the pipeline script output
Write a print statement to display the contents of the pipeline_script variable.
Jenkins
Need a hint?

Use print(pipeline_script) to show the pipeline code.