In Jenkins pipelines, shared libraries help reduce duplication by:
- A) Copying pipeline code into every job automatically
- B) Forcing each pipeline to rewrite common steps
- C) Centralizing reusable code that multiple pipelines can call
- D) Removing the need for any pipeline scripts
Think about how one place for code helps many pipelines.
Shared libraries store common pipeline code in one place. Pipelines call this code instead of duplicating it, reducing repetition and easing maintenance.
Which of these best describes a direct benefit of using shared libraries in Jenkins pipelines?
Think about maintenance and updates.
When common code is centralized in shared libraries, updating that code updates all pipelines that use it, making maintenance easier.
Even with shared libraries, some Jenkins pipelines still have duplicated code. What is a likely cause?
Consider developer habits and usage.
If developers copy code from shared libraries into pipelines instead of calling the library functions, duplication still happens.
Which practice best helps reduce duplication when using Jenkins shared libraries?
Think about centralizing reusable code.
Keeping reusable code in shared libraries and calling it from pipelines avoids duplication and makes maintenance easier.
Given this Jenkins pipeline snippet calling a shared library function sayHello() that prints 'Hello from library!':
pipeline {
agent any
stages {
stage('Test') {
steps {
script {
sayHello()
}
}
}
}
}What will be the console output during the 'Test' stage?
Assume the shared library is properly configured and loaded.
The shared library function sayHello() prints 'Hello from library!' when called in the pipeline.