Vert.x Travis Setup
Pages 161
Clone this wiki locally
|
Important
|
due to the decreasing QoS of Travis CI for open source project, the CI is migrated to GitHub actions |
Vert.x Travis CI setup
How to add a new project?
The Vert.x project lead is the only one in the GitHub org with repo admin rights. So the first step is asking the lead to enable the project:
-
enable the repository on Travis
-
set the Sonatype credentials as environment variables for the build
Projects are listed here:
The second step is to copy the Travis descriptors in the project repo:
-
.travis.yml -
.travis.maven.settings.xml -
.travis.deploy.artifacts.sh
The third step is to adapt the configuration in .travis.yml: you might need specific services to run
(see Builds using Docker section).
The last step is to commit and push your changes.
Template descriptors
The following descriptors are used by Travis to build the repository jobs:
dist: xenial
language: java
before_install:
- cp .travis.maven.settings.xml $HOME/.m2/settings.xml
- sudo apt-get update -qq
- sudo apt-get install --only-upgrade openjdk-8-jdk
branches:
only:
- master
- /^\d+\.\d+$/
cache:
directories:
- $HOME/.m2 (1)
before_cache:
- rm -rf $HOME/.m2/repository/io/vertx/ (2)
jobs:
include:
- stage: test
name: "OpenJDK 8"
jdk: openjdk8
install: true (3)
script: mvn -q clean verify -B
- if: type != pull_request (4)
name: "OpenJDK 11"
jdk: openjdk11
install: true
script: mvn -q clean verify -B
- stage: deploy
name: "Deploy to Sonatype's snapshots repository"
jdk: oraclejdk8
if: type != pull_request AND env(SONATYPE_NEXUS_USERNAME) IS present
install: true
script: bash .travis.deploy.artifacts.sh
notifications:
email:
recipients:
- secure: <ENCRYPTED EMAIL RECIPIENT> (5)
on_success: always
on_failure: always-
maven dependencies are cached and shared between jobs with same
os,distributionandjdk -
avoid caching
io.vertxdependencies -
avoid unnecessary
mvn installrun -
we don’t build pull requests with OpenJDK11 to minimise the Travis load
-
notifications use an encrypted variable, so forks won’t notify the list, see notifications section
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<interactiveMode>false</interactiveMode>
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>${env.SONATYPE_NEXUS_USERNAME}</username>
<password>${env.SONATYPE_NEXUS_PASSWORD}</password>
</server>
</servers>
</settings>PROJECT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version -B | grep -v '\[')
if [[ "$PROJECT_VERSION" =~ .*SNAPSHOT ]] && [[ "${TRAVIS_BRANCH}" =~ ^master$|^[0-9]+\.[0-9]+$ ]] && [[ "${TRAVIS_PULL_REQUEST}" = "false" ]];
then
mvn deploy -s .travis.maven.settings.xml -DskipTests -B;
fiSpecific branches builds
Travis builds all branches by default, we want to restrict the CI to only build the master branch and the maintenance branches following the convention x.y where x is a major version and y a minor version, e.g 3.6 .
branches:
only:
- master
- /^\d+\.\d+$/Those are the only branches the CI should build.
Deploying snapshots
If the commit verification phase succeeds, we need to publish the artifacts to Sonatype’s Nexus snapshot repository. But we don’t want this to happen when the version
-
is not a snapshot (release commit in master or in x.y branch )
-
for pull requests builds
-
for repository forks, to allow forks run their own build using Travis and not fail
The following file is executed after the commit was verified:
PROJECT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version -B | grep -v '\[')
if [[ "$PROJECT_VERSION" =~ .*SNAPSHOT ]] && [[ "${TRAVIS_BRANCH}" =~ ^master$|^[0-9]+\.[0-9]+$ ]] && [[ "${TRAVIS_PULL_REQUEST}" = "false" ]];
then
mvn deploy -s .travis.maven.settings.xml -DskipTests -B;
fiThe credentials for authentication at Sonatype are set as environment variables in the Travis settings interface.
When a build is executed, Travis will decrypt values and set them in environment Then Maven can connect to Sonatype with the following server settings:
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>${env.SONATYPE_NEXUS_USERNAME}</username>
<password>${env.SONATYPE_NEXUS_PASSWORD}</password>
</server>
</servers>Notifications
The vertx3-CI google group is notified with build results from the original repository only. In order to prevent forks notifying this list, the list is encrypted using Travis so only the original repository will send notifications, here is the notification block that is used
notifications:
email:
recipients:
- secure: <ENCRYPTED EMAIL RECIPIENT>
on_success: always
on_failure: alwaysThe encrypted email recipient can be created using the Travis CLI:
travis encrypt -r vert-x3/vertx-shell vertx3-ci@googlegroups.comBuilds using Docker
To use Docker in the build, the service needs to be enabled in the YAML file:
services:
- dockerThen you can run Docker commands in any phase. Here’s an example from the vertx-mysql-postgresql-client module:
before_install:
- docker run -e POSTGRES_USER=vertx -e POSTGRES_PASSWORD=password -e POSTGRES_DB=testdb -p 5432:5432 -d postgres
- docker run -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -e MYSQL_USER=vertx -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=testdb -p 3306:3306 -d mysqlTroubleshooting
TCP capture
It can be useful to capture the network traffic to understand a particular failure that would not occur locally.
You can use tcpdump to create a capture, this example captures the network frames on the localhost interface on port 8080 in the wireshark format.
script:
- sudo apt-get install tcpdump
- sudo tcpdump -i lo -s 65535 -w capture.pcap port 8080 &
...This will create a capture.cap file, to get this file it needs to be uploaded somewhere using Travis.