|
7 | 7 | "keywords": "Plone, continuous integration, best practices"
|
8 | 8 | ---
|
9 | 9 |
|
10 |
| -# Essential continuous integration practices |
| 10 | +# Continuous Integration |
11 | 11 |
|
12 |
| -The {term}`CI` system at [jenkins.plone.org](https://jenkins.plone.org) is a shared resource for Plone core developers to notify them of regressions in Plone core code. |
| 12 | +As a complex system build out of hundreds of small packages, Plone can be easily broken, inadvertently, with any change on any of its packages. |
13 | 13 |
|
14 |
| -Build breakages are a normal and expected part of the development process. |
15 |
| -The aim is to find errors and remove them as quickly as possible, without expecting perfection and zero errors. |
16 |
| -However, there are some essential practices that you need follow to achieve a stable build: |
| 14 | +For that a mix of a {term}`CI` system at [jenkins.plone.org](https://jenkins.plone.org) and GitHub Actions ensure that any change is thoroughly checked. |
17 | 15 |
|
| 16 | +## Jenkins |
18 | 17 |
|
19 |
| -## 1) Don't check in on a broken build |
| 18 | +Jenkins is the primary source of truth to know if the complete test suite of any Plone versions in development is passing or not. |
20 | 19 |
|
21 |
| -Do not make things more complicated for the developer who is responsible for breaking the build. |
| 20 | +Jenkins is configured to react on changes done in any of the hundreds of repositories that all together make Plone. |
22 | 21 |
|
23 |
| -If the build breaks, the developer has to identify the cause of the breakage as soon as possible and should fix it. |
24 |
| -This strategy gives the developer the best option to find out what caused the breakage and fix it immediately. |
25 |
| -Fixing the build is easier with a clear look at the problem. |
26 |
| -Checking in further changes and triggering new builds will complicate matters and lead to more problems. |
| 22 | +Whenever a change on any of those repositories happen, Jenkins starts a slew of testing jobs that ultimately answer the question of if those changes pass Plone's test suite. |
27 | 23 |
|
28 |
| -If the build is broken over a longer period of time (more than a couple of hours) you should either: |
| 24 | +### Triggering jobs (automatically) |
29 | 25 |
|
30 |
| -- notify the developer who is responsible for the breakage |
31 |
| -- fix the problem yourself |
32 |
| -- revert the commit so you and others can continue to work |
| 26 | +As running the Jenkins jobs is a bit expensive, in time, Jenkins does not run automatically on any new commit. |
33 | 27 |
|
34 |
| -```{note} |
35 |
| -There is one exception to this rule. |
36 |
| -Sometimes there are changes or tests that depend on changes in other packages. |
37 |
| -If this is the case, there is no way around breaking a single build for a certain period of time. |
38 |
| -In this case, run the all tests locally with all the changes and commit them within a time frame of ten minutes. |
39 |
| -``` |
40 |
| - |
41 |
| - |
42 |
| -## 2) Always run all commit tests locally before committing |
43 |
| - |
44 |
| -Follow this practice so the build stays green, and other developers can continue to work without breaking the first rule. |
45 |
| - |
46 |
| -Remember that Plone development can happen all over the world, at all times. |
47 |
| -Other developers may have checked in changes since your last synchronization. |
48 |
| -These may interact with your work. |
49 |
| - |
50 |
| -Therefore it's essential that you merge changes from the main branch into your feature branch, then run the tests again, before you push your changes to GitHub. |
51 |
| - |
52 |
| -A common source of errors on check-in is to forget to add some files to the repository. |
53 |
| -Use {command}`git status` to check and correct for this. |
54 |
| -Also double-check to not check in files that should not be part of a package, such as editor configuration files and git submodules. |
| 28 | +Rather, Jenkins waits for a special comment to be found in a pull request on a repository that is monitored by Jenkins. |
55 | 29 |
|
| 30 | +```text |
| 31 | +@jenkins-plone-org please run jobs |
| 32 | +``` |
56 | 33 |
|
57 |
| -## 3) Wait for commit tests to pass before moving on |
58 |
| - |
59 |
| -Always monitor the build's progress, and fix the problem right away if it fails. |
60 |
| -If you introduced a regression, you have a far better chance of fixing the build sooner than later. |
61 |
| -Also another developer might have committed in the meantime (by breaking rule 1), making things more complicated for you. |
62 |
| - |
63 |
| - |
64 |
| -## 4) Never go home on a broken build |
65 |
| - |
66 |
| -Take into account the first rule of CI ("Don't check in on a broken build"). |
67 |
| -Breaking the build essentially stops all other developers from working on it. |
68 |
| -Therefore going home on a broken build—or even on a build that has not finished yet—is _not_ acceptable. |
69 |
| -It will prevent all other developers from working, or they will need to fix the errors that you introduced. |
| 34 | +Pasting the text above on a pull request, will trigger Jenkins to run all configured test suites related to the current pull request, **with the changes of the pull request itself**. |
70 | 35 |
|
| 36 | +#### buildout.coredev special case |
71 | 37 |
|
72 |
| -## 5) Always be prepared to revert to the previous revision |
| 38 | +`buildout.coredev` is the special repository where our configuration and tooling to orchestrate Plone lies in. |
73 | 39 |
|
74 |
| -For other developers to work on the build, you should always be prepared to revert to the previous passing revision. |
| 40 | +Contrary to all the other repositories, whenever a commit is made on this repository, it automatically triggers Jenkins jobs to be run. |
75 | 41 |
|
| 42 | +### Triggering jobs (manually) |
76 | 43 |
|
77 |
| -## 6) Time-box fixing before reverting |
| 44 | +Jenkins jobs can also be triggered manually by going to our Jenkins server, login in with your GitHub account, finding the right job, and triggering the `Run` button. |
78 | 45 |
|
79 |
| -When the build breaks on check-in, try to fix it for ten minutes. |
80 |
| -If, after ten minutes, you aren't finished with the solution, revert to the previous version from your version control system. |
81 |
| -This way you will allow other developers to continue to work. |
| 46 | +### Results |
82 | 47 |
|
| 48 | +Once a jenkins job is finished, it will update its status icon on Jenkins UI itself, but also report back to GitHub, the result of the job. |
83 | 49 |
|
84 |
| -## 7) Don't comment out failing tests |
| 50 | +For pull requests, this means a green check mark or a red cross will be displayed at the end of the pull request, on pull requests listings, even on the favicon itself. |
85 | 51 |
|
86 |
| -Once you begin to enforce the previous rule, the result is often that developers start commenting out failing tests in order to get the build passing again as quickly as possible. |
87 |
| -While this impulse is understandable, it is _not acceptable_. |
| 52 | +This gives the expected feedback to the pull request author, or any reviewer interested in knowing how a given pull request fared in Jenkins. Thus allowing pull request reviewers or authors to decide if the pull request can already be merged. |
88 | 53 |
|
89 |
| -The tests were passing for a while and then start to fail. |
90 |
| -This means that you either caused a regression, made assumptions that are no longer valid, or the application has changed the functionality being tested for a valid reason. |
| 54 | +#### On failures |
91 | 55 |
|
92 |
| -You should always either fix the code (if a regression has been found), modify the test (if one of the assumptions has changed), or delete it (if the functionality under test no longer exists). |
| 56 | +If the Jenkins jobs reports failures, the statuses of the pull request will provide a `Details` link back to Jenkins. |
93 | 57 |
|
| 58 | +That link leads back to the Jenkins job build for that pull request. |
94 | 59 |
|
95 |
| -## 8) Take responsibility for all breakages that result from your changes |
| 60 | +In that page, there is the list of test failures (if any) already listed. Clicking on them show the stacktrace that should help diagnose why there was an error on a given test. |
96 | 61 |
|
97 |
| -If you commit a change and all the tests you wrote pass, but others break, the build is still broken. |
98 |
| -This also applies to tests that fail in `buildout.coredev` and don't belong directly to the package you worked on. |
99 |
| -This means that you have introduced a regression bug into the application. |
| 62 | +On the side bar of the job build page in Jenkins there is also `Console Output` link. This leads to the **full job output**, note that is large, where it can be seen all the steps and debugging information that Jenkins generated running the job. |
100 | 63 |
|
101 |
| -It is _your responsibility_ to fix all tests that do not pass because of your changes. |
| 64 | +This can be helpful whenever the errors where not on a single test, but rather a general testing set up/tear down problem. |
102 | 65 |
|
103 |
| -There are some tests in Plone that fail randomly, and the community is always working on fixing those. |
104 |
| -If you think you hit such a test, try to fix it or re-run the Jenkins job to see if it passes again. |
| 66 | +### Retrying |
105 | 67 |
|
106 |
| -In any case, the developer who made the commit is responsible to make it pass. |
| 68 | +If there were errors on the Jenkins jobs, and corrections have been made on the code, triggering the jenkins jobs again is a matter of giving the special comment on the GitHub pull request again: |
107 | 69 |
|
| 70 | +```text |
| 71 | +@jenkins-plone-org please run jobs |
| 72 | +``` |
108 | 73 |
|
109 |
| -## Further reading |
| 74 | +Jenkins jobs can also be restarted within Jenkins UI itself. On the Jenkins job itself, and provided you are logged in, you can find a `Retry` link on the left toolbar. Clicking it will trigger a new Jenkins job with the same configuration as the one you are on. |
110 | 75 |
|
111 |
| -These rules were taken from the excellent book "Continuous Delivery" by Jez Humble and David Farley (Addison Wesley), and have been adopted and rewritten for the Plone community. |
| 76 | +Jenkins will update GitHub statuses accordingly. |
0 commit comments