-
Notifications
You must be signed in to change notification settings - Fork 37
CI Best Practices
-
Keep builds and tests FAST!
- 10 minutes are fast, 3 hours are not
- Create robust tests, do not rely on best-case-scenario timeouts
- Always use reasonable job timeouts
- Disable concurrent builds
- Use webhook triggers
- If that's not possible, use the "poll scm" option
- Don't do plain periodical builds (nightly builds)
- Keep your build history at a reasonable length, do not keep more than 5 builds with artifacts
- Clean out your old/deprecated build jobs regularly
See also CI_best_practices
- Use Jenkinsfiles (commit pipeline definitions to SCM)
- Use declarative pipelines, use scripted syntax only as a last resort
- For complex pipelines, consider shared libraries
See also https://www.cloudbees.com/blog/top-10-best-practices-jenkins-pipeline-plugin
Tycho 1.4 calculates bundle timestamps from the git history much faster than the versions before (you may see improvements of some seconds per Maven aggregator module). Besides that, also all your other tools (Maven, Maven Plugin, JDK, ...) should be on the most recent level possible with the target environment restrictions of your project.
Check at least "draft" and "private" in the Gerrit trigger section for changes to be excluded from automatic builds.
When archiving artifacts, scanning for test reports and so on, avoid using a double asterisk wildcard for "any directory". That can take a huge amount of time. In almost all cases we can easily specify the path with single wildcard, like */target/report/*.xml
Always run maven with --batch-mode
(or -B
) to get rid of the many lines of download progress in the console. Will avoid several MB of log output with each build, making it easier for you to diagnose builds and easier for Jenkins to store them.
You can also completely remove all information about download and upload by setting the system property -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
. This can also be set in an environment variable MAVEN_OPTS
.
Note: On the new clustered infrastructure, both the --batch-mode
and the system property Slf4jMavenTransferListener
are set in all provided agents via MAVEN_OPTS
and MAVEN_CONFIG
environment variables.
Tycho plugins are not marked thread-safe. Nevertheless, many projects use parallel Maven builds with Tycho without problems. If you take this route, make sure that only one UI test can run at any given time (e.g. there is only a single executor on the same node). If you feel confident after a while, you may even want to disable the non-thread-safe warnings using -Dorg.slf4j.simpleLogger.log.org.apache.maven.lifecycle.internal.builder.BuilderCommon=error
.
On nodes that are re-used for multiple builds, do not delete the Jenkins workspace at the start/end of the build. Otherwise, you have to clone the repository again on the next build. It's faster to use git reset -fdx
instead.
Important: This tip does not apply to dynamic agents on our clustered infrastructure, as agents are ephemeral and workspaces are eventually lost at the end of the builds. Deleting Jenkins workspaces at the end of the build is then a waste of time, as this will be done by the system anyway after the agent is shutdown.
Your build may create documentation, online help, source features, sign artifacts and many other things in addition to compilation and test. Use Maven profiles to disable most of those additional build steps for Gerrit builds. Only build those on the master branch after merging the Gerrit change. Of course, there is a trade-off here between how often your master branch may break and how much time you can save in Gerrit builds.
From a green build, open the test results tab. Click the table header to sort by execution time. Starting from the top, look for rows with a little number of contained test methods. Optimize/delete these tests, they are eating too much time per test case.
If you configure jobs via pipeline, you probably want to configure them for performance instead of durability.
Note: On our clustered infrastructure, the default pipeline durability is already set to performance
by default on all Jenkins instances.