Jenkins Notes 1700451057
Jenkins Notes 1700451057
JENKINS
INTERVIEW
NOTES
Interview Success Strategies and Knowledge
Nuggets
Jatin Shharma
51 Jenkins Interview Questions
3. Install Java
7. Give name and select ‘Permanent Agent’ and click on ‘create’ button
10. Execute these command one by one on the server and make sure to check the IP
address is same for jenkins and commands
11. Before executing commands ,Go to the sudo mode by using sudo su
15. Create ‘Freestyle Project’ in Jenkins. make sure to select ‘Restrict where this Project
can be run’ and select the label.
19. Check the server if the file that we added on the freestyle project is available or not
Note:
Please note that if the server is disconnected and then reconnected, the IP address will
change. Consequently, the IP address will also need to be updated in the following
command:
java -jar agent.jar -jnlpUrl http://35.154.111.176:8080/computer/dev/jenkins-agent.jnlp -
secret 91c89bd63cf846b66e97a23dde986b468c58b43933bdd02826bbf4d9330b8cb6 -
workDir ""
Ensure to modify the IP address accordingly before executing the command after the server
reconnection.
• Poll SCM: Polling SCM involves checking the source code repository for changes at
regular intervals. When changes are detected, Jenkins triggers a build. Polling SCM is
event-driven and depends on changes in the repository.
• Yes, you can run different jobs on different types of Jenkins slaves (nodes/agents).
• You can label your slaves with tags (e.g., "QA" or "Dev"), and then in your job
configuration, specify which label a job should run on.
• Jenkins will schedule the job on an appropriate slave based on the label you've
defined.
• [Refer Jenkins Master slave setup]
• Jenkins is a popular open-source automation server that's crucial for Continuous Integration
(CI) and Continuous Delivery (CD) in software development.
• Its core purpose is to automate tasks like building, testing, and deploying software, making
development faster and more reliable.
• Jenkins also offers a vast selection of plugins to customize and extend its functionality.
Continuous Integration, often abbreviated as CI, is a software development practice and process. It
revolves around the idea of frequently integrating code changes made by multiple developers into a
shared codebase. The core principles of CI include:
• Frequent Integration: Developers regularly merge their code changes into a central
repository, multiple times a day if possible. This ensures that everyone's work is
continuously integrated.
• Automated Build and Testing: As code changes are integrated, an automated CI system
kicks in. It automatically builds the software and runs a suite of tests, including unit tests and
integration tests, to identify issues and ensure that the code functions correctly.
• Isolation of Changes: CI encourages small, focused code changes. If a problem arises during
integration, it's easier to pinpoint the specific code change that caused the issue, making
debugging and fixing problems more efficient.
• Version Control: Version control systems, like Git, are essential in CI. They allow developers
to track changes, collaborate effectively, and revert to previous code states if necessary.
• Deployment Readiness: CI pipelines often include tasks related to preparing code for
deployment to various environments, ensuring that the code is always in a deployable state.
The primary benefits of CI include early issue detection, consistent and reproducible builds, faster
development cycles, and improved collaboration among development teams. CI ultimately
contributes to higher software quality and more reliable releases
Error Handling Provides some built-in error handling. Requires explicit error handling code.
Built-in Features Fewer built-in features and functions. Offers a wide range of built-in functions.
Declarative Pipeline:
In a Declarative Pipeline, you can access environment variables using the environment block.
Here's an example:
pipeline {
agent any
environment {
MY_VARIABLE = 'some_value'
stages {
stage('Example Stage') {
steps {
In this example, we define the MY_VARIABLE environment variable within the environment block,
and then we access it using ${env.MY_VARIABLE} within the echo step.
Scripted Pipeline:
In a Scripted Pipeline, you can access environment variables directly using the env object.
Here's an example:
node {
In this example, we assign the value of the MY_VARIABLE environment variable to a variable
called myVariable, and then we echo its value.
Jenkins automatically provides several environment variables that you can access, such as
BUILD_NUMBER, JOB_NAME, WORKSPACE, and many more. You can also set your custom
environment variables as shown in the examples above.
o Declarative and Scripted Syntax: Jenkins supports two types of syntax for
defining pipelines within Jenkinsfiles: Declarative and Scripted. Declarative
syntax is more structured and easy to read, while Scripted syntax provides
more flexibility and control through Groovy scripting.
• The most efficient way to trigger Jenkins on code commits is by setting up a webhook in
your version control system. This webhook will send a notification to Jenkins whenever a
commit is made to the repository.
• In GitHub or Gitlab, for example, you can go to your repository's settings, select
"Webhooks," and add a new webhook that points to your Jenkins server's webhook URL
19. How can you ensure that Jenkins jobs are triggered in a
specific order?
• Use the "Build after other projects are built" option in the job configuration to define the
dependencies between jobs.
23. How can you schedule a Jenkins job to run at a specific time?
• In Jenkins, the "workspace" refers to a directory on the Jenkins master or agent node
where a specific job's files and build artifacts are stored during the execution of that job.
Each Jenkins job has its own dedicated workspace, and this workspace is used to store
the source code, build scripts, and any other files required for the job's build or
automation process.
• Jenkins Remote API (HTTP Requests): You can use HTTP POST requests to trigger a Jenkins
job remotely. For example, you can use tools like curl or scripts to send a POST request to
the job's URL.
• Jenkins CLI (Command Line Interface): The Jenkins CLI allows you to trigger jobs from the
command line using commands like build or build-job.
• Webhooks: If you want to trigger jobs automatically based on external events (e.g., code
pushes), you can set up webhooks. When an event occurs, such as a code push to a
repository, a webhook can trigger the associated Jenkins job.
• Scheduled Builds (Polling): Jenkins supports scheduled builds, where you can configure a
job to poll a version control system for changes and trigger a build when changes are
detected.
• Third-Party Plugins: Jenkins has a rich ecosystem of plugins. Some plugins, like the "GitHub
Plugin" or "GitLab Plugin," allow you to trigger Jenkins jobs as a result of specific events in
your version control system.
• Authentication and Security: Security is critical when triggering jobs remotely. You need to
configure proper authentication and authorization mechanisms in Jenkins to ensure that
only authorized users or systems can initiate job builds.
o Version Control: Pipeline configurations are stored in code files (e.g., Jenkinsfiles),
which can be versioned using a source code management system (e.g., Git). This
enables you to track changes, collaborate with others, and roll back to previous
configurations if needed.
• Code Reusability: Shared Libraries allow teams to define and share common functions,
steps, and resources, reducing duplication of code across projects. This promotes the
'Don't Repeat Yourself' (DRY) principle and makes it easier to manage and update shared
functionality.
• Encapsulation of Complexity: Complex logic, integration with external tools, and custom
business processes can be encapsulated within a Shared Library. This simplifies pipeline
configurations in individual projects, making them more readable and maintainable.
• Version Control: Shared Libraries can be version-controlled using tools like Git, allowing
teams to track changes, roll back to previous versions, and manage library releases
effectively.
• Security and Compliance: Shared Libraries can include security and compliance checks,
ensuring that all pipelines using the library adhere to necessary security and compliance
standards.
33. How can you integrate Jenkins with Docker for build and
deployment?
• Use Docker plugins or Docker commands within Jenkins pipeline stages to build, test, and
deploy Docker containers.
46. How can you trigger a Jenkins pipeline on a Git branch other
than the default?
• Use the Git plugin along with branch specifier in the job configuration to trigger the
pipeline on a specific branch.
51. How can you trigger a Jenkins job remotely using a token?
• Use a URL in the format JENKINS_URL/job/JOB_NAME/build?token=TOKEN_NAME to trigger
a job remotely with a specific token.