Sign in Join
Wiki copytemporary

Jenkins: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Jenkins

OldNewLine
1+## Overview
2+
3+Jenkins is a continuous integration server that can be used to automatically build and test projects based on commits to your source control system.
4+
5+This article describes how to set up Jenkins to automatically build FPC when a commit happens in SVN. You can of course adapt these instructions to your own projects.
6+
7+## Jenkins set up
8+
9+A possible version to use is Turnkey Linux Jenkins on Debian 6.0.5 (Squeeze); this article tested with Jenkins 1.464)
10+
11+Whichever way you install Jenkins, make sure the SVN plugin is enabled
12+
13+## Resource compiler setup
14+
15+At least the Debian FPC packages don't install a [[Lazarus Resources|resource compiler]], which is needed in sections below:
16+
17+``` bash
18+# Get resource compiler, not provided by fpc 2.6 packages:
19+apt-get install mingw32-binutils
20+# symlink:
21+ln -s /usr/bin/i586-mingw32msvc-windres /usr/bin/windres
22+```
23+
24+## Database driver setup
25+
26+For testing database connections/writing results to databases, make sure the relevant operating system database drivers/client connection libraries are installed, e.g.:
27+
28+``` bash
29+apt-get install libfbembed2.5 firebird2.5-super firebird2.5-dev \
30+postgresql-client libpq-dev \
31+freetds-bin freetds-dev \
32+mysql-client libmysqlclient-dev \
33+libsqlite3-0 libsqlite3-dev \
34+unixodbc unixodbc-dev tdsodbc #adjust to taste/distribution
35+# we install the -dev packages so we get the correct driver names for older FPC versions (e.g. libfbclient.so.2.5 instead of libfbclient). Alternatively: symlink these or specify explicit .so names in any code using databases
36+#freetds should pull in unixodbc, but we specify it explicitly.
37+#Strangely, on Debian, we need to explicilty specify tdsodbc to get the actual FreeTDS ODBC driver!?
38+```
39+
40+## Setting up jobs
41+
42+Use the job screen to set the svn source to the FPC trunk or branch you want to use (e.g. <http://svn.freepascal.org/svn/fpc/trunk>)
43+
44+Set 'use svn update as much as possible'
45+
46+Polling every 5 minutes could be a good setup. Alternatively, you can set up your own SVN server and write a commit hook script for that. This would result in this entry:
47+
48+``` bash
49+# every 20 minutes
50+*/20 * * * *
51+```
52+
53+## Background: the regular build & problems
54+
55+> **Note:** This section is included for completeness; problems with system wide fpc.cfg and current FPC trunk (October 2012) may make using fpcup much easier. See below for that.
56+
57+### Stable FPC setup
58+
59+Install binutils+resource compiler+stable FPC - for some reason the debian packages don't pull in the required dependencies:
60+
61+``` bash
62+apt-get install build-essential mingw32-binutils
63+# now make an easier name for the resource compiler; adjust to your specific version
64+# you could also adjust -FC<resourcecompilername> in /etc/fpc.cfg
65+ln -s /usr/bin/i586-mingw32msvc-windres /usr/bin/windres
66+
67+#fpc would get old FPC 2.4 on this Debian Squeeze=> symptom in Jenkins build log:
68+#generic.inc(2505,13) Fatal: Internal error 8
69+#Fatal: Compilation aborted
70+#make[7]: *** [system.ppu] Error 1
71+
72+#get stable compiler (2.6 at time of writing); we're on a 32 bit system:
73+cd /root
74+wget http://sourceforge.net/projects/freepascal/files/Linux/2.6.0/deb/fp-compiler-2.6.0_2.6.0-0_i386.deb/download
75+mv download fp-compiler-2.6.0_2.6.0-0_i386.deb
76+wget http://sourceforge.net/projects/freepascal/files/Linux/2.6.0/deb/fp-compiler_2.6.0-0_i386.deb/download
77+mv download fp-compiler_2.6.0-0_i386.deb
78+wget http://sourceforge.net/projects/freepascal/files/Linux/2.6.0/deb/fp-units-rtl_2.6.0-0_i386.deb/download
79+mv download fp-units-rtl_2.6.0-0_i386.deb
80+wget http://sourceforge.net/projects/freepascal/files/Linux/2.6.0/deb/fp-units-rtl-2.6.0_2.6.0-0_i386.deb/download
81+mv download fp-units-rtl-2.6.0_2.6.0-0_i386.deb
82+wget http://sourceforge.net/projects/freepascal/files/Linux/2.6.0/deb/fp-units-i386-2.6.0_2.6.0-0_i386.deb/download
83+mv download fp-units-i386-2.6.0_2.6.0-0_i386.deb
84+wget http://sourceforge.net/projects/freepascal/files/Linux/2.6.0/deb/fp-units-i386_2.6.0-0_i386.deb/download
85+mv download fp-units-i386_2.6.0-0_i386.deb
86+wget http://sourceforge.net/projects/freepascal/files/Linux/2.6.0/deb/fp-utils-2.6.0_2.6.0-0_i386.deb/download
87+mv download fp-utils-2.6.0_2.6.0-0_i386.deb
88+wget http://sourceforge.net/projects/freepascal/files/Linux/2.6.0/deb/fp-utils_2.6.0-0_i386.deb/download
89+mv download fp-utils_2.6.0-0_i386.deb
90+
91+dpkg -i fp-units-rtl-2.6.0_2.6.0-0_i386.deb
92+dpkg -i fp-units-rtl_2.6.0-0_i386.deb
93+dpkg -i fp-compiler-2.6.0_2.6.0-0_i386.deb
94+dpkg -i fp-utils-2.6.0_2.6.0-0_i386.deb
95+#no idea what the other .debs are for that we downloaded
96+#todo: this could be trimmed down a bit, but this seems to work
97+```
98+
99+### Jenkins build commands
100+
101+As build commands in Jenkins, you could use the shell commnds
102+
103+``` bash
104+make all
105+```
106+
107+and, to install inside the "workspace" or top of the build directory environment:
108+
109+``` bash
110+make install PREFIX=$WORKSPACE
111+```
112+
113+Note: installing somewhere else may be a good idea, please refer to the Build FAQ.
114+
115+Make install does not generate an fpc.cfg for you; you have to do that yourself:
116+
117+``` bash
118+$WORKSPACE/bin/fpcmkcfg -o $WORKSPACE/bin/fpc.cfg
119+```
120+
121+### A problem: /etc/fpc.cfg
122+
123+The stable we compiled using packages works, but puts an fpc.cfg into the /etc directory. This fpc.cfg is picked up by default and there is no way to disable that unless you e.g. call a script fpc.sh as your compiler instead of the fpc executable. This script passes options to the real compiler so it ignores /etc/fpc.cfg
124+
125+This will give problems with running e.g. the compiler test suite. These problems may be solved by:
126+
127+- use an PPC_CONFIG_PATH environment variable or fpc.cfg in home dir, which may work.
128+- perhaps a simpler solution is just not to install FPC/FPC sources, but only download a bootstrap compiler. Therefore no fpc.cfg, and no problem. Bonus is that we build it closer to the "official way". (which is a full install of the previous release)
129+
130+To work around is, you can also use fpcup; see the next section.
131+
132+### A problem: make clean
133+
134+Current (October 2012) FPC trunk does not clean all relevant files when running make clean/make distclean.
135+
136+## Solution: getting FPC using fpcup
137+
138+The [[Projects using Lazarus|fpcup]] tool can download and install FPC and Lazarus from scratch (no starting compiler needed), so a solution could be:
139+
140+- get fpcup into your workspace
141+- change build steps to call fpcup with --only=fpc --fpcrevision=\$SVN_REVISION
142+
143+We could have run fpcup so it downloads the latest SVN version, but then we lose the integration with subversion.
144+
145+Make sure you have a resource compiler (see installation section above). Download fpcup (bitness should match your Jenkins machine). Put e.g. fpcup_linux_x86 in your /usr/local/bin directory, then:
146+
147+``` bash
148+chmod ugo+rx /usr/local/bin/fpcpup_linux_x86
149+```
150+
151+(If using an x64 Linux, naming will obviously differ)
152+
153+Then set your build steps like this. Note: we could have used one big shell script, but the advantage of putting the commands in execute shell commands is that the build will stop on the first error (non-zero exit status) encountered; you'd have to build that error detection into a script.
154+
155+``` bash
156+rm --force $WORKSPACE/fpcup.log #remove any existing logs; use force to not generate error message if log does not exist
157+```
158+
159+Download/install using fpcup. Note it gets the SVN URL and desired revision ID from environment variables set by the Jenkins SVN plugin. Once again, adjust if you don't use x86 Linux.
160+
161+``` bash
162+/usr/local/bin/fpcup_linux_x86 --fpcbootstrapdir=$WORKSPACE/fpcbootstrap --fpcdir=$WORKSPACE --fpcuplinkname= --fpcURL=$SVN_URL --fpcrevision=$SVN_REVISION --keeplocalchanges --lazdir=$WORKSPACE/lazarus --lazlinkname= --logfilename=$WORKSPACE/fpcup.log --noconfirm --primary-config-path=$WORKSPACE/lazarusconfig --only=fpc
163+```
164+
165+Now check the fpc output in another build step. Note that fpcup uses a custom fpc.sh script to avoid problems with systemwide fpc.cfg. Once again, adjust if not on Linux x86.
166+
167+``` bash
168+$WORKSPACE/bin/i386-linux/fpc.sh -iD; $WORKSPACE/bin/i386-linux/fpc.sh -iW #get FPC version output to check if it was built correctly
169+```
170+
171+The last build step runs the "compiler test suite".
172+
173+``` bash
174+cd $WORKSPACE/tests; make all TEST_FPC=$WORKSPACE/bin/i386-linux/fpc.sh #make full doesn't work, can't delete file
175+```
176+
177+You could archive the test suite results using a Jenkins post-build step.
178+
179+## FPCUnit/DBTestframework tests with database output
180+
181+If you want to run the [[Databases|dbtestframework]] tests and output the results to a separated database server, you can use the testdbwriter programs. This lets you compare runs from various revisions - which are automatically built by Jenkins.
182+
183+This method of outputting test results to databases can also be used by other projects that use fpcunit tests - you'd have to use the testdbwriter listener and adjust the console runner to include that.
184+
185+Though this section contains a fair amount of setup, fortunately it is once only; each job will reuse the existing configuration.
186+
187+You could of course also run the normal dbtestframework code with output to plain text or XML.
188+
189+Check if mercurial/hg is installed:
190+
191+``` bash
192+hg --help
193+```
194+
195+if not install it, e.g.
196+
197+``` bash
198+apt-get install mercurial
199+```
200+
201+Get the repository version into a fixed directory:
202+
203+``` bash
204+mkdir -p /opt/testdbwriter
205+cd /opt
206+hg clone https://bitbucket.org/reiniero/testdbwriter #will create /opt/testdbwriter
207+cd /opt/testdbwriter
208+# the following 2 steps are not necessary but show you how you can update with newest changes in the repository if needed:
209+hg pull #get newest changes from remote repo
210+hg up #adapt local version to newest changes we just downloaded
211+```
212+
213+### Database setup
214+
215+Now the files in this directory can be used to compile the test program with the FPC in each build. We will also need to setup our database connections.
216+
217+#### Tested databases
218+
219+First the databases where the tests will run on. Please create an empty database (or at least one that the test user can thrash) on each db server that you want to test, and have a username and password ready.
220+
221+Then edit database.ini, used by the db test framework tests (see [[Databases|Databases#Running_FPC_database_tests]]
222+
223+``` bash
224+cd /opt/testdbwriter/dbtests2db
225+cp database.ini.txt database.ini #copy over template to config file
226+nano database.ini # or another editor.
227+# now set up your credentials in each section
228+```
229+
230+#### Test results database
231+
232+Now the database where the results should go to.
233+
234+Set up a database with the instructions pointed to in the readme.txt file (e.g. use the *testdbwriter.sql* for Firebird/Interbase databases and *testdbwriter_postgresql.sql* for PostgreSQL databases).
235+
236+Now edit the ini file:
237+
238+``` bash
239+cd /opt/testdbwriter/dbtests2db
240+cp ../testdbwriter.ini.txt testdbwriter.ini #copy over template to config file
241+nano testdbwriter.ini #or another editor
242+# now set up your credentials in the right section, and choose your profile/database in the [Database] section
243+```
244+
245+### Adding the tests to your Jenkins job
246+
247+We'll put the dbtests2db.lpr console runner and the db output writer code it needs (testdbwriter.pas) into the directory where the dbtestframework tests live so dbtests2db can pick up those tests. Then we'll compile the test suite, and run it for each database you want to test.
248+
249+In your Jenkins job configuration, add an Execute shell build step to set up the test environment. Note: we copy forcing overwrites to avoid the script aborting the Jenkins job if the target exists:
250+
251+``` bash
252+cp -f /opt/testdbwriter/testdb* \
253+/opt/testdbwriter/dbtests2db/database.ini \
254+/opt/testdbwriter/dbtests2db/dbtests2db.lpr \
255+-t $WORKSPACE/packages/fcl-db/tests/; \
256+cd $WORKSPACE/packages/fcl-db/tests; \
257+$WORKSPACE/bin/i386-linux/fpc.sh $WORKSPACE/packages/fcl-db/tests/dbtests2db.lpr \
258+#copy & compile db test program using the fpc dbtestframework tests
259+```
260+
261+Then for each database you want to test, add test runs. The names of the database connectors you specify as arguments must match the section names in database.ini, e.g. postgresql, mysql40, mysql41, mysql50, oracle, interbase etc.
262+
263+> **Note:** The dbtests2db program requires that the database connector is the first parameter; we also pick up the subversion revision number from the Jenkins subversion module we use. The examples below show how you can add more information to the test results database.
264+
265+If you are testing multiple branches/versions of FPC (e.g. 2.6 and trunk) at the same time, you have a problem: the SVN revision number does not apply to branches but to the whole repository.
266+
267+This means that the code in the FPC fixes26 branch commit 2500 may be older than the code in the FPC trunk branch 2300. Fortunately, there is a solution: we prepend the revision number passed to the executable with a value (e.g. 020701 for FPC 2.7.1, 020600 for FPC 2.6.0). This serves to preserve the relative "newness" of the various branches... and permits running regression queries on the database to show e.g. that FPC trunk has a failing test where 2.6.0 succeeded.
268+
269+> **Note:** Older versions of this instruction proposed using
270+>
271+> ``` bash
272+> --svnbranch="trunk"
273+> ```
274+>
275+> which can also be done, but then you separate your testsuite hierarchies into different trees in the database. This does not allow running regression queries so easily.
276+
277+Examples:
278+
279+``` bash
280+cd $WORKSPACE/packages/fcl-db/tests; \
281+$WORKSPACE/packages/fcl-db/tests/dbtests2db interbase --revisionid=020701$SVN_REVISION --comment="Jenkins trunk interbase"
282+```
283+
284+With MySQL, as usual, the client version you installed on the Jenkins server has to match the version you specify here - in the example version 5.1:
285+
286+``` bash
287+cd $WORKSPACE/packages/fcl-db/tests; \
288+$WORKSPACE/packages/fcl-db/tests/dbtests2db mysql51 --revisionid=020701$SVN_REVISION --comment="Jenkins trunk mysql51"
289+```
290+
291+``` bash
292+cd $WORKSPACE/packages/fcl-db/tests; \
293+$WORKSPACE/packages/fcl-db/tests/dbtests2db postgresql --revisionid=020701$SVN_REVISION --comment="Jenkins trunk postgresql"
294+```
295+
296+``` bash
297+cd $WORKSPACE/packages/fcl-db/tests; \
298+$WORKSPACE/packages/fcl-db/tests/dbtests2db sqlite --revisionid=020701$SVN_REVISION --comment="Jenkins trunk sqlite"
299+```
300+
301+``` bash
302+cd $WORKSPACE/packages/fcl-db/tests; \
303+$WORKSPACE/packages/fcl-db/tests/dbtests2db bufdataset --revisionid=020701$SVN_REVISION --comment="Jenkins trunk bufdataset"
304+```
305+
306+``` bash
307+cd $WORKSPACE/packages/fcl-db/tests; \
308+$WORKSPACE/packages/fcl-db/tests/dbtests2db dbase4 --revisionid=020701$SVN_REVISION --comment="Jenkins trunk dbase4"
309+```
310+
311+Note: with all this building and testing, your job running time may extend a bit. Please make sure you set the SVN polling interval to a big enough value to avoid building all the time.
312+
313+If this works, you can see the test results on your database server, analyze regressions, test succcess percentages, etc.
314+
315+## Windows/Linux... build slave
316+
317+You can set up other machines apart from the Jenkins server to act as "slaves": they are controlled from Jenkins and used to run jobs.
318+
319+This can be useful when running a Windows build/test run from a Linux server.
320+
321+See [1](https://wiki.jenkins-ci.org/display/JENKINS/Windows+slaves+fail+to+start+via+DCOM) for details on how to set up Windows build slaves via DCOM (note: there are other ways to set up (Windows) build slaves; please refer to the Jenkins documentation)
322+
323+## Enhancements
324+
325+Possible enhancements:
326+
327+- run make install into a different prefix
328+- run Lazarus compile
329+- save dbtests2db results to XML, see if Jenkins supports that
330+- add installer builders
331+
332+## Troubleshooting
333+
334+### Build fails
335+
336+Your builds may fail because the user Jenkins runs under runs a different shell under a different user with a different path than you might expect.
337+
338+### Find out which user Jenkins runs under
339+
340+If you have problems with scripts/shell commands in jobs not having permissions, it helps if you know which user Jenkins runs under. Try this command (or of course the documentation):
341+
342+``` bash
343+ps aux |grep jenkins | grep -v grep | cut -d" " -f1 | uniq #perhaps only works if jenkins is running a job
344+```
345+
346+On Debian, it gives the tomcat6 user.
347+
348+## See also
349+
350+- [[Build server]]
351+
352+## External links
353+
354+- [First look on Jenkins pipelines with a simple Lazarus application](https://medium.com/@Zawuza/first-look-on-jenkins-pipelines-with-a-simple-lazarus-application-36c77af56829)
355+
356+---
357+*From the Free Pascal wiki, page "Jenkins", as it stood on 2022-08-16 after a change by Skalogryz, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
358+Category: CI/CD

Back to history