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: svl-products-rails
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
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
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.