Think of everything we have started to put into our automated builds:
and, coming up, we will want to expand our testing to include
There’s a danger of the builds becoming so unwieldy and slow that programmers will start to look for ways to circumvent steps,
Do We Need to do All of Those Steps, All of the Time?
One possible breakdown:
Every build | Occasional |
---|---|
fetching and setup of 3rd party libraries | documentation generation |
static analysis | static analysis reports |
compilation | deployment/publication of artifacts |
unit testing | updating of project website |
packaging of artifacts | integration testing |
test coverage reporting | |
system testing |
This should provide someone actively working on a specific module/story the info they need, deferring some of the more time-consuming build activities.
How do we divide these steps in the build?
Even the “occasional” activities may be done many times over the history of a project.
So we want to keep them automated, both for ease of performing them and to ensure they are performed consistently each time.
With make
/ant
/maven
, we can have different targets/goals for the frequent and the occasional cases.
But there’s an opportunity here to do something much more interesting…
When we combine
we can rebuild and retest automatically as developers check in changes.
Our project should have the characteristics:
Version control with a clearly identified main branch or set of main development branches.
Automated build is set up as usual.
Developers commit frequently (maybe many times per day)
Testing is done, ideally, in a clone of the production environment(s)
Make the results highly visible
A CI system consists of a server/manager and one or more runners…
A continuous integration server is a network-accessible machine that
Can be told of development projects under way, including
Monitors, in some fashion, the VC repository for commits
When a commit (to a monitored branch) takes place, the CI server notifies one or more runners.
A CI runner (a.k.a., nodes or slave processors) is a process on a machine that
has the the necessary compilers and other tools for building a project.
is managed by the CI server.
When notified by the server, the runner
Checks out a designated branch of a project from its version control system.
Runs the build.
Publishes reports on the results of the build(s).
Runners are usually separate machines from the CI server.
A CI project may launch several different runners, each with a different configuration environment (e.g., different operating systems) to test the build under multiple configurations.
Jenkins is a popular CI server.
When you set up a project on Jenkins you must supply:
Basic project info:
Version control:
Build management:
(I usually add a special “jenkins
” target to my Ant
build.xml
files.)
Which of Jenkin’s nodes can be used for the build.
Reporting
Many report-generating programs (e.g., JUnit, FindBugs, etc.) have separate “collection” and “reporting” stages.
Typically the collection step writes raw data out in an XML format.
Normally, you then run a separate task to reformat that XML into HTML or some other readable format.
Jenkins, however, has its own formatting functions for many common reports.
Among other things, these often add “historical” reporting on how the collected data has varied over a period of time.
gitlab-ci
is a CI server integrated into Gitlab.
Project build status is integrated into the version control activity reports,
Click on Green checkmarks and Red X’s to see successful and failed builds.
Setup is generally easier if your project is already hosted on Gitlab.
Project must activate gitlab-ci
by designating a runner, generally on a remote machine under the developer’s control.
Add a file gitlab-ci.yml
to the repository root directory.
This is a YAML script that gets run after each new commit.
Script can limit which branches it applies to
Example:
stages:
- build
- test
- deploy
build-job:
tags:
- atria
stage: build
script:
- echo build number is $CI_BUILD_REF
- cd report_accumulator
- ./gradlew build deployReports -Dorg.gradle.project.buildNumber=$CI_BUILD_REF
only:
- master
The “script:” part gives the build commands to be run on the runner machine.
Reporting
Jenkins provides fancier reporting options. It composes a nice-looking project summary page.
Such activities must be scripted as part of the build to work in gitlab-ci.
Flexibility
Jenkins has a definite Java bias.
gitlab-ci can run any language you can script a build for.
Setup
Jenkins setup can be confusing.
gitlab-ci setup is easier, but requires a properly setup remote runner.
Runners:
Continuous deployment publishes snapshots of deliverables as changes are checked in.
Some organizations actually wire up build light indicators to provide a highly visible indicator of the status of the latest integration build.