Calliope Jenkins integration¶
It's possible to integrate Calliope into your Jenkins pipeline. As a matter of fact, it's quite easy. We'll be looking into create a very basic Jenkins pipeline, as well as integrating a simple Ruby Cucumber test script and uploading its results to Calliope. Please note that this tutorial was written based on a Linux Ubuntu environment, it may work slightly different on Windows or Macintosh.
Prerequisites¶
You need to have Jenkins and Ruby installed on your machine.
- Install Ruby here.
Info
For this example, Ruby 2.7 was used with the Cucumber gem.
- Install Jenkins here.
Creating a new Jenkins pipeline¶
For information on how to integrate Jenkins into a Gitlab pipeline, please see this tutorial.
Pipeline code¶
In the tutorial from the previous chapter you will create a new pipeline inside your Gitlab repository. Use this code instead of the code in the tutorial and edit its environment variables to your situation:
pipeline {
agent any
environment{
API_KEY = <YOUR_API_KEY>
PROFILE_ID = <YOUR_PROFILE_ID>
}
stages {
// First we install bundler and the required dependencies.
stage('setup') {
steps {
sh 'gem install bundler'
sh 'bundle install'
}
}
// Then we run the tests and export the results to a file called 'output.json'.
stage('test') {
steps {
sh 'bundle exec cucumber -f json -o output.json -f pretty -c || true'
}
}
// Lastly we upload the exported results to Calliope.
stage('upload') {
steps {
sh 'curl -X POST ' +
'-H "x-api-key:${API_KEY}" ' +
'-H "multipart/form-data" '+
'-F "file[]=@output.json" ' +
'"https://test.calliope.pro/api/v2/profile/${PROFILE_ID}/import/cucumber?tag[]=myos&tag[]=myplatform&tag[]=mybuild"'
}
}
}
}
Info
As mentioned before, this was based on a Linux Ubuntu environment. For example, on Windows you may have to use "bat" instead of "sh".
Jenkins pipelines separate each major action with stages. This pipeline contains 3 stages:
- Setup: here we install Bundler and the other required gems for the Ruby project.
- Test: here we run the tests themselves. How long these take of course depend on the amount of tests, and their complexity.
- Upload: lastly we upload the results of the Cucumber tests to Calliope.
The following variables are defined inside the pipeline:
API_KEY
: Required to import tests to Calliope.pro. Can be found on your Calliope.pro account pagePROFILE_ID
: Tests will be imported in one of your profiles on Calliope.pro. You can find the ID in the curl command (see below).
The 'sh:' part is the command that is going to run when the job gets triggered.
bundle exec cucumber -f json -o output.json -f pretty -c || true
runs all the Cucumber tests and stores the results in 'output.json'.|| true
makes sure the next commands are also executed when a test fails, because it cancels the whole pipeline otherwise.curl -X POST ...
will import the tests into the Calliope.pro platform.
Formatter endpoints
It is recommended to add the formatter to the endpoint to obtain the best interpreted results. More information about the recommended formatters here.
Make sure the file output.json
points to the results file you generated.
Result¶
You can choose to run this pipeline on your Jenkins environment by clicking "Build now" on the overview of your pipeline. It will give an output similar to this:
For more information on Jenkins, please read its official documentation.