Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add best practices page #6478

Merged
merged 64 commits into from Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6934554
Add to _chapter and add docs
JE-Chen May 26, 2023
c1b4f8d
Add Administering Jenkins
JE-Chen May 26, 2023
61d9fa0
Update administering-jenkins.adoc
JE-Chen May 26, 2023
e074703
Update administering-jenkins.adoc
JE-Chen May 26, 2023
a01cc91
Merge branch 'master' into master
JE-Chen May 26, 2023
35f1490
Merge branch 'master' into master
JE-Chen May 26, 2023
b8f98b3
Merge branch 'master' into master
JE-Chen May 26, 2023
e7b2ed7
Merge branch 'master' into master
JE-Chen May 26, 2023
6de675d
Refactor doc string
JE-Chen May 30, 2023
8f74a84
Merge branch 'master' into master
JE-Chen May 30, 2023
e0b2928
Merge branch 'master' into master
JE-Chen May 30, 2023
0d4e650
Merge branch 'master' into master
JE-Chen May 31, 2023
e74ecfa
Merge branch 'master' into master
JE-Chen Jun 1, 2023
62a170d
Merge branch 'master' into master
JE-Chen Jun 1, 2023
b5d6691
Merge branch 'master' into master
JE-Chen Jun 1, 2023
9acd331
Merge branch 'master' into master
JE-Chen Jun 5, 2023
b12fe1c
Merge branch 'master' into master
JE-Chen Jun 6, 2023
d2b631f
Merge branch 'master' into master
JE-Chen Jun 8, 2023
3d746f5
Merge branch 'master' into master
JE-Chen Jun 12, 2023
b5a64e4
Add example picture and edit text.
JE-Chen Jun 12, 2023
9b71588
Edit text
JE-Chen Jun 12, 2023
3f26f91
Merge branch 'master' into master
JE-Chen Jun 12, 2023
00434df
Merge branch 'master' into master
JE-Chen Jun 13, 2023
b0e6a8a
Merge branch 'master' into master
JE-Chen Jun 14, 2023
2fab3ac
Merge branch 'master' into master
JE-Chen Jun 16, 2023
b4411d9
Merge branch 'master' into master
JE-Chen Jun 17, 2023
2eb88ab
Extract section to another page.
JE-Chen Jun 17, 2023
453a9c7
Fix title and add to _chapter.yml
JE-Chen Jun 17, 2023
65bb012
Make link on next line not same as intro.
JE-Chen Jun 17, 2023
80fafff
Don't need the relative motion in URL
MarkEWaite Jun 17, 2023
c6ce851
Simplify JENKINS_HOME description
MarkEWaite Jun 17, 2023
a856943
Add an introductory sentence
MarkEWaite Jun 17, 2023
c09eca9
Another sentence of introduction
MarkEWaite Jun 17, 2023
a1f10ff
Merge branch 'master' into master
JE-Chen Jun 17, 2023
26499f8
Move creating-project to working-with-projects
MarkEWaite Jun 17, 2023
420d529
Merge branch 'JE-Chen-mwaite-modified/master' into JE-Chen-COPY/master
MarkEWaite Jun 17, 2023
937ad20
Include table of contents in the page
MarkEWaite Jun 17, 2023
5af18cc
Revise directory content based on current layout
MarkEWaite Jun 17, 2023
d1d8b53
Remove new page added as administering-jenkins
MarkEWaite Jun 17, 2023
f6b2992
Remove administering-jenkins
MarkEWaite Jun 17, 2023
ac97756
Remove unused image
MarkEWaite Jun 17, 2023
b768662
Remove unused image
MarkEWaite Jun 17, 2023
2a5a8aa
Sort entries in the directory contents list
MarkEWaite Jun 17, 2023
5bf9efe
Merge branch 'master' into add-best-practices-page
MarkEWaite Jun 17, 2023
ec4308c
Remove the working-with-projects content
MarkEWaite Jun 17, 2023
a4edf8c
Simplify phrasing and embed videos
MarkEWaite Jun 17, 2023
be8bdd3
Rephrase reproducible builds, remove archiving jobs
MarkEWaite Jun 17, 2023
896ba13
Apply code review phrasing improvements
MarkEWaite Jun 21, 2023
2d593fe
Capitalize section header correctly
MarkEWaite Jun 21, 2023
4d0ac9b
Merge branch 'master' into add-best-practices-page
MarkEWaite Jun 21, 2023
33b9e6e
Merge branch 'master' into add-best-practices-page
MarkEWaite Jun 22, 2023
25ec994
Remove trailing spaces
MarkEWaite Jun 22, 2023
fd16ddc
Merge branch 'master' into add-best-practices-page
MarkEWaite Jul 7, 2023
501269a
Use standard case for headings
MarkEWaite Jul 7, 2023
345149e
Add more words to the Pipeline practice
MarkEWaite Jul 7, 2023
24a66e6
Do not use Maven job type
MarkEWaite Jul 7, 2023
f2809df
Automate job definition as top level heading
MarkEWaite Jul 7, 2023
5c75084
Add more videos and use more sections
MarkEWaite Jul 7, 2023
fb6b355
Add more videos and organization of best practices
MarkEWaite Jul 7, 2023
cbff611
Apply suggestions from Bruno's review
MarkEWaite Jul 7, 2023
e93e9da
Apply suggestions from Kevin's and Bruno's review
MarkEWaite Jul 7, 2023
0b99f21
Merge branch 'master' into add-best-practices-page
MarkEWaite Jul 7, 2023
9861247
Fix hyperlink
MarkEWaite Jul 13, 2023
ab66349
Merge branch 'master' into add-best-practices-page
MarkEWaite Jul 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions content/doc/book/using/_chapter.yml
@@ -1,5 +1,6 @@
---
sections:
- best-practices
- working-with-projects
- using-credentials
- searchbox
Expand Down
192 changes: 192 additions & 0 deletions content/doc/book/using/best-practices.adoc
@@ -0,0 +1,192 @@
---
layout: section
title: Best Practices
---
ifdef::backend-html5[]
:description:
:author:
:sectanchors:
:toc:
:toclevels: 4
:hide-uri-scheme:
ifdef::env-github[:imagesdir: ../resources]
ifndef::env-github[:imagesdir: ../../resources]
endif::[]

Continuous Integration (CI) with automated test execution and trend analysis has revolutionized the way companies approach build management, release management, deployment automation, and test orchestration.
In this section, we will explore best practices that aim to enlighten executives, business managers, software developers, and architects about the invaluable contributions Jenkins can make throughout the project lifecycle.

== Automate job definition

Jenkins has the ability to automatically create, update, and delete jobs based on the repositories it identifies in your software configuration management system.
Leverage this feature and optimize your job management by structuring your job definitions in a way that maximizes the benefits offered by Jenkins' automatic job management capabilities.

There are multiple alternatives for automatic job management, including:

* <<Use organization folders>> - create, update, and delete multibranch Pipeline folders and Pipeline jobs automatically (preferred)
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
* <<Use multibranch Pipelines>> - create, update and deleted Pipeline jobs automatically
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
* <<Pipeline>> - Manually defined Pipeline jobs for more control over the job management process.
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved

=== Use organization folders

Organization Folders provide a convenient way to automate the creation and deletion of jobs in Jenkins as repositories and branches are added or removed.
If you are using GitHub organizations, Bitbucket teams, GitLab groups, or Gitea organizations, Jenkins can automatically detect the creation of a new repository and generate a Multibranch Pipeline project for it.

Refer to the link:/doc/book/pipeline/pipeline-as-code/#organization-folders[organization folders] documentation for more details.

.GitHub organization folders
video::LbXKUKQ24T8[youtube,width=800,height=420]

.GitLab group folders
video::it6TOeQ6EHg[youtube,width=800,height=420]

.Bitbucket project folders
video::85b6fiVolfk[youtube,width=800,height=420]

.Gitea organization folders
video::NO3sZWRxgQM[youtube,width=800,height=420]

=== Use multibranch Pipelines

If you are unable to use organization folders, you can opt for multibranch Pipelines as an alternative.
However, it's important to note that organization folders are preferred over multibranch Pipelines because they provide the automation of creating and deleting multibranch projects when repositories are added or removed.

.GitHub multibranch Pipelines
video::aDmeeVDrp0o[youtube,width=800,height=420]

.GitLab group folders
video::y4XGFluzPHY[youtube,width=800,height=420]

.Bitbucket project folders
video::LNfthmZuRDI[youtube,width=800,height=420]

Refer to the link:/doc/book/pipeline/pipeline-as-code/#multibranch-pipeline-projects[multibranch Pipelines] documentation for more details.

=== Use Pipeline

If organization folders are not an option for you, consider using multibranch Pipelines as an alternative.
However, it's important to highlight that organization folders are preferred, due to their ability to automatically create and delete multibranch projects when repositories are added or removed.

Refer to the link:/doc/book/pipeline/[Pipeline] documentation for more details.

.Differences between Freestyle and Pipeline in Jenkins
video::IOUm1lw7F58[youtube,width=800,height=420]

== Manage your jobs

Jenkins job definitions can be managed and optimized to enhance user interactions and productivity.

=== Report build results

Charts and graphs provide valuable insights into project status and progress, showcasing trends and patterns.
Automated test results including unit tests, integration tests, and end-to-end tests can reveal brittleness or instability.
Coverage reports help identify areas where automated tests are not being executed.
Compiler warning messages often serve as the first indication of a problem.
Static analysis tools are effective in reporting risky code or code with potential security risks.
Performance test results help identify delays or areas of concern.

The plugin:warnings-ng[Warnings Next Generation] plugin provides convenient access to many reports including:

* Compiler warnnings and errors (like gcc, clang, javac, or golang)
* Static analysis warnings and errors (spotbugs, checkstyle, pmd, lint, cpd, or Simian)
* Code coverage reports

.How to use the Warnings Next Generation plugin
video::tj3xYFA6Q2o[youtube,width=800,height=420]

=== Build on agents

Use agents to perform builds instead of running builds on the controller.
MarkEWaite marked this conversation as resolved.
Show resolved Hide resolved
Utilizing agents offers enhanced safety and scalability.

Refer to the link:/doc/book/security/controller-isolation/[controller isolation] documentation for more details.

=== Show failures to the right people

Configure notifications for failing and unstable jobs, to ensure that the right people receive them without causing unnecessary distractions for others.
Many Jenkins users prefer to be notified only when a failure is likely their responsibility.
This approach acknowledges that if they are not responsible for the failure, they may not be the most suitable person to investigate it.

Refine your notification system to prioritize notifying the most recent committers when new test failures occur, as they are likely to be the cause of the issue.

.Sending Slack notifications
video::EDVZli8GdUM[youtube,width=800,height=420]

=== Use simple project names

Jenkins utilizes project names for organizing related folders.
However, it's important to note that certain tools may encounter issues with spaces, dollar signs, or similar characters in file paths.
To ensure compatibility, it's recommended to limit project names to alphanumeric characters` [a-zA-Z0-9_-]+`.
To enhance the appearance of project names, you can utilize the *Display Name* feature.
This allows you to customize the presentation, while maintaining the restricted characters in the underlying project name.
To enforce consistent naming conventions across all projects, enable the "Restrict project naming" setting in the system configuration.
This ensures that naming restrictions are enforced uniformly.

=== Fingerprint your dependencies

When dealing with interdependent projects, it can be challenging to keep track of which version of one project is used by another.
However, Jenkins offers a solution called "file fingerprinting" to simplify this process.

Refer to the link:/doc/book/using/fingerprints/[fingerprinting page] for more information.

=== Don't use the Maven job type

Jenkins has been providing the plugin:maven-plugin[Maven integration plugin] for many years, allowing users to create Maven projects using the "Maven project" selection from the Jenkins "New item" menu.
While the Maven job type offers a higher level of integration with Maven builds, it can sometimes introduce unnecessary complexities due to this deep integration.

Consider using organization folders, multibranch Pipelines, or Pipeline jobs instead of the Maven job type.
These alternatives provide more flexibility and simplicity in managing your Jenkins jobs and workflows.

The Jenkins project uses organization folders to build link:https://ci.jenkins.io/job/Core/[Jenkins core] and link:https://ci.jenkins.io/job/Plugins/[Jenkins plugins] on ci.jenkins.io.
A Jenkins Pipeline builds Maven projects easily and provides much better control for Maven users.

Refer to the link:https://plugins.jenkins.io/maven-plugin/#plugin-content-risks[Maven plugin documentation] for more details.

== Manage your controller

The Jenkins controller plays a crucial role as a central resource, requiring effective management for optimal performance.
By following these practices, you can ensure that your controller provides the best possible experience for users.

=== Secure the controller

Jenkins installations come with security enabled by default, which is a crucial aspect of protecting your system.
While it is technically possible to disable security, it is strongly advised **not** to do so.
Disabling security can leave your Jenkins instance vulnerable to unauthorized access and potential security breaches.
It is important to maintain a secure environment by keeping security enabled at all times.

Refer to the link:/doc/book/security/securing-jenkins/[securing Jenkins] chapter of the User Handbook for more details.

=== Back up regularly

Even the most reliable systems can experience failures.
That's why it's crucial to be prepared and regularly check the health of your backups.
Backups are a critical component of ensuring the integrity and availability of your data.
Regularly testing your backups and verifying their completeness and restorability will help you mitigate the impact of any potential failures and ensure that your data can be recovered effectively when needed.
kmartens27 marked this conversation as resolved.
Show resolved Hide resolved
Prioritizing backup health and conducting routine checks is essential for maintaining a robust and resilient system.

More details can be found in the link:/doc/book/system-administration/backing-up/[backup documentation].

=== Avoid scheduling overload

Schedule your jobs strategically to balance the number of jobs running concurrently.
If you're using timer triggers or periodic polling, consider using the `H` syntax in the cron expression to introduce scheduling jitter.
This helps to distribute the start times of jobs more evenly and prevent them from all starting simultaneously.
Additionally, take advantage of predefined tokens like `@hourly` to further distribute the starting times of your jobs.
These tokens can help create a more balanced schedule and reduce the likelihood of resource contention.

By implementing these scheduling techniques, you can optimize the utilization of your resources and ensure a smoother execution of your jobs.

=== Avoid resource collisions

When multiple jobs run simultaneously, there is a possibility of collisions occurring, especially if they require exclusive access to certain resources or set-up services.
To prevent interference and ensure smooth execution, it is important to manage resource access effectively.
For builds involving databases or networked services, it is crucial to implement measures that prevent conflicts.
The plugin:lockable-resources[Lockable Resources plugin] offers fine-grained resource-locking capabilities for Jenkins jobs.
By using this plugin, you can ensure that only one job has access to a specific resource at a time, avoiding conflicts and ensuring proper synchronization.
In cases where resource locking with the lockable resources plugin is not sufficient, you can further control concurrent builds using the plugin:throttle-concurrent-builds[Throttle Concurrent Builds plugin].
This plugin allows you to limit the number of builds that can run simultaneously, providing additional control and preventing overload on shared resources.

By leveraging these plugins, you can manage resource conflicts and concurrency effectively, ensuring smooth and reliable execution of your Jenkins jobs.

.How to use lockable resources
video::y_z8mqV8G68[youtube,width=800,height=420]