This a Jenkins library built to make it easier for us at Wolox to configure pipelines without necessarily knowing about Jenkinsfile syntax. All our projects are built using a Dockerfile
When using this library, your Jenkinsfile should look something like this:
@Library('wolox-ci') _
node {
checkout scm
woloxCi('.woloxci/config.yml');
}
It basically loads the library, clones the target repository and calls woloxCi
to make its magic.
As an argument, woloxCi
receives the path to a configuration yaml file.
This file looks something like this:
config:
dockerfile: .woloxci/Dockerfile
project_name: some-rails-project
services:
- mssql
steps:
analysis:
- bundle exec rubocop -R app spec --format simple
- bundle exec rubycritic --path ./analysis --minimum-score 80 --no-browser
setup_db:
- bundle exec rails db:create
- bundle exec rails db:schema:load
test:
- bundle exec rspec
security:
- bundle exec brakeman --exit-on-error
audit:
- bundle audit check --update
environment:
RAILS_ENV: test
GIT_COMMITTER_NAME: a
GIT_COMMITTER_EMAIL: b
LANG: C.UTF-8
jenkinsEnvironment:
- JENKINS_URL
timeout: 600
This file has different sections:
The section under the config
label defines some basic configuration for this project:
- The dockerfile that contains the image for the project to run.
- The project name.
This section lists the project's dependencies. Each section will define and expose some environment variables that might be needed by the application:
When listing mssql
as a service, this will build a docker image from microsoft/mssql-server-linux
exposing the following environment variables:
- DB_USERNAME
- DB_PASSWORD
- DB_HOST
- DB_PORT
When listing postgres
as a service, this will build a docker image from postgres
exposing the following environment variables:
- DB_USERNAME
- DB_PASSWORD
- DB_HOST
- DB_PORT
When listing redis
as a service, this will build a docker image from redis
exposing the following environment variables:
- REDIS_URL: the redis url that looks like this
redis://redis
When listing mysql
as a service, this will build a docker image from mysql
exposing the following environment variables:
- DB_USERNAME
- DB_PASSWORD
- DB_HOST
- DB_PORT
When listing mongo
as a service, this will build a docker image from mongo
exposing the following environment variables:
- DB_USERNAME
- DB_PASSWORD
- DB_HOST
- DB_PORT
When listing elasticsearch:6.4.0
as a service (it's mandatory specify the image version), this will build a docker image from elasticsearch
exposing the following environment variables:
- ELASTICSEARCH_URL
This section lets you define the steps you need to build your project. Each level inside the steps
section is a stage in the Jenkins pipeline and each item in the stage is a command to run. In the case above, there are 5 stages named:
- analysis
- setup_db
- test
- security
- audit
The analysis stage, for example, runs the following commands:
bundle exec rubocop -R app spec --format simple
bundle exec rubycritic --path ./analysis --minimum-score 80 --no-browser
This section lets you set up custom environment variables. Each item inside this section defines a variable with its value.
This section lets you define what Jenkins environment values you want to pass to the docker image, i.e. JENKINS_URL. Bear in mind that, for convenience, Wolox CI already passes the following Jenkins Environment Variables to the Docker image by default:
- BUILD_ID
- BRANCH_NAME
- CHANGE_ID
- CHANGE_BRANCH (if job is PR-triggered)
- CHANGE_TARGET (if job is PR-triggered)
This section lets you set up a custom timeout in seconds. The default is 600 (10 minutes).