InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is a Ping Thread in Jenkins and how it works? |
|
Answer» Jenkins installs "ping THREAD" on every remote connection, such as Controller/Agent connections, regardless of its transport mechanism (such as SSH, JNLP, etc.). The lower level of the Jenkins Remoting Protocol is a message-oriented protocol, and a ping thread PERIODICALLY sends a ping message that the receiving end will reply to. The ping thread measures the time it TAKES for the reply to arrive, and if it’s taking excessive time (currently 4 minutes and configurable), then it assumes that the connection was lost and initiates the formal close down. This is to avoid an infinite hang, as some of the failure modes in the network cannot be detected otherwise. The timeout is also set to a long enough value so that a temporary surge in the load or a long garbage COLLECTION pause will not trip off the close-down. Ping thread is installed on both controller & agent; each side pings the other and tries to detect the problem from their sides. The ping thread time out is reported through java.util.logging. Besides, the controller will also report this exception in the agent launch log. Note that some agent launchers, most notably SSH agents, writes all stdout/stderr outputs from the agent JVM into this same log file, so you need to be careful. ConclusionThough these are not the complete possibilities of Jenkins, we tried to cover some of the commonly asked interview questions on core Jenkins. We also need to understand that the Jenkins Update Center is enriched with thousands of useful plugins that enhance the supported functionalities of Jenkins. Before appearing for an interview, make sure to install a Jenkins Server on any of the supported platforms - either locally or on the cloud, install the most common plugins (suggested by Jenkins itself & other commonly used plugins). Try creating & building a normal freestyle project with Git or any other SCM integration plugin and try to execute some code from the connected Git Repository. Also, try creating a pipeline project with JenkinsFile and a global shared Jenkins library and build the job successfully. This will help us learn how Jenkins actually works with some hands-on issues. |
|
| 2. |
Can we monitor Jenkins using common Observability tools? |
|
Answer» COMMON monitoring platforms like DataDog, Prometheus, JavaMelody & few others - have their corresponding Jenkins plugin, which when configured, sends Metrics to the corresponding Monitoring platform, which can then be Observed with the latest tools & technologies. The same can be configured with ALARMS & Notifications for immediate attention when something GOES wrong. |
|
| 3. |
What is In-process Script Approval and how it works? |
|
Answer» Jenkins, and SEVERAL plugins, allow users to execute Groovy scripts in Jenkins. To protect Jenkins from the execution of malicious scripts, these plugins execute user-provided scripts in a Groovy Sandbox that limits what internal APIs are accessible. This protection is provided by the Script SECURITY plugin. As soon as an unsafe METHOD is used in any of the scripts, the "In-process Script Approval" ACTION should appear in "Manage Jenkins" to allow Administrators to make a decision about which unsafe methods, if any, should be allowed in the Jenkins environment. This in-process script approval inherently IMPROVES the security of the overall Jenkins ecosystem. |
|
| 4. |
What is Jenkins Remote Access API? |
|
Answer» Jenkins provides remote access API to most of its functionalities (though some functionalities are programming language-dependent). Currently, it comes in three flavors -
Remote access API is offered in a REST-like STYLE. That is, there is no single entry point for all features, and INSTEAD, they are available under the ".../api/" URL where the "..." portion is the data that it acts on. For example, if your Jenkins installation sits at interviewbit.com, visiting /api/ will show just the top-level API features available – PRIMARILY a LISTING of the CONFIGURED jobs for this Jenkins instance. Or if we want to access information about a particular build, e.g. https://ci.jenkins.io/job/Infra/job/jenkins.io/job/master/lastSuccessfulBuild/, then go to https://ci.jenkins.io/job/Infra/job/jenkins.io/job/master/lastSuccessfulBuild/api/ and you’ll see the list of functionalities for that build. |
|
| 5. |
How to download the Console log for a particular Jenkins build programmatically? |
|
Answer» Using the JENKINS CLI - console - command java -jar jenkins-cli.jar console JOB [BUILD] [-f] [-N N] Produces the console OUTPUT of a specific build to stdout, as if you are doing 'cat build.log'
E.g. ssh -l <ssh_username> -p <port_no> <Jenkins_URL> console <JOB_NAME> |
|
| 6. |
How to install a Custom Jenkins Plugin or a Version of Plugin Not available in Jenkins Update Center? |
|
Answer» Generally, it is the best practice to use the latest version of a plugin. But there are ways to install custom plugins or outdated versions of a published plugin. Jenkins Plugins are exported using a .hpi file and the same can be installed in multiple ways - Using the Jenkins CLI java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin SOURCE ... [-DEPLOY] [-name VAL] [-restart] The above command Installs a plugin either from a file, an URL or from the update center.
ADVANCED Installation - via - Web UI Assuming a .hpi file has been downloaded, a logged-in Jenkins administrator may upload the file from within the web UI:
Advanced Installation - via - On the master Assuming a .hpi file has been explicitly downloaded by a systems administrator, the administrator can manually place the .hpi file in a specific location on the file system. Copy the downloaded .hpi file into the JENKINS_HOME/plugins directory on the Jenkins controller (for example, on Debian systems JENKINS_HOME is generally /var/lib/jenkins). The master will need to be restarted before the plugin is loaded and made available in the Jenkins environment. |
|
| 7. |
How to create & use a Shared Library in Jenkins? |
|
Answer» Basic requirements for a Jenkins shared library to be used in a Pipeline CODE are -
E.g. #!/urs/bin/env groovy |
|
| 8. |
How to do Global Tools Configuration in Jenkins? |
|
Answer» Global Tools are tools that need to be installed outside the Jenkins environment and need to be controlled from WITHIN the Jenkins environment. Hence it needs its corresponding Jenkins plugin as well. Steps to using a Global TOOL generally include -
|
|
| 9. |
How can a job configuration be reset to an earlier version/state? |
|
Answer» From the Job DETAILS page, we can USE Job Config HISTORY to - See diff, Review & Revert the Job configs from the history of changes we have made to a PARTICULAR job. This will be super useful when a job is misconfigured by someone by mistake, it can be REVIEWED and reverted easily to any of its earlier states. |
|
| 10. |
Default Environment Variables by Jenkins & How to introduce custom environment variables? |
|
Answer» JENKINS PROVIDES SEVERAL environment variables by default like - BRANCH_NAME, BUILD_NUMBER, BUILD_TAG, WORKSPACE, etc. |
|
| 11. |
How code coverage is measured/tracked using Jenkins in a CI environment? |
|
Answer» Using language-specific code COVERAGE plugins LIKE JaCoCo, CodeCov, etc or generic tools/plugins like Sonarqube which will add the code coverage data to builds with some minor TWEAKS in the code and the same can be DISPLAYED as a GRAPH in Jenkins. |
|
| 12. |
How can we share information between different build steps or stages in a Jenkins Job? |
|
Answer» Every BUILD STEP or stage will be running in its process and hence SHARING information between TWO different build steps is not so direct. We can use either a FILE, a Database Entry, an Environment Variable, etc. to share info from one build step to another or a post-build action. |
|
| 13. |
How to configure inclusions & exclusions in Artifacts Archival? |
|
Answer» ARTIFACT archival TAKES in a pattern for matching target files. Similarly, it also takes in a pattern (ANT BUILD system pattern for matching files) for exclusion as WELL which will be ignored while selecting the files for archival. For e.g. The above command will archive all the TEXT files from the output folder except specific_file.txt |
|
| 14. |
What is Artifact Archival & how to do it in Pipelines? |
|
Answer» Artifacts are the exportable/storable/archivable results of a specific job build. This can be configured USING a PLUGIN called - Copy artifact Plugin. BASED on the configured pattern, the files/directories matching the configured patterns will be archived for a Jenkins build, which can be used for future references. In the PIPELINE, it can be configured as follows - archiveArtifacts artifacts: 'output/**/*' |
|
| 15. |
How is continuous integration achieved using Jenkins? |
|
Answer» Continuous integration is a process where a developer’s code changes are constantly integrated into the main code and the same will be tested automatically and the results of the tests will decide whether the change is ready for deployment. In this process -
|
|