Jenkins Integration

DBmarlin can link to Jenkins so that you can relate database performance to changes such as code releases and deployments triggered by Jenkins jobs.

Enable the integration

To enable the integration you can add an extra build step to any Jenkins job to execute a shell command.

https://d33wubrfki0l68.cloudfront.net/98df34d5b5129113bb33ef751e6d6b8ea57fdcb2/6aa4a/img/jenkins-dbmarlin-event.jpg

Shell command to execute

The code below will run on any Jenkins node running Linux with the curl command installed. Just customize the hashmap at the top of the script to set a comma separated list of values (dbmarlin_host, instance_id, event_type_id) that you want to send to.

declare -A hashmap
#hashmap contains comma separated list of values (dbmarlin_host, instance_id, event_type_id)
hashmap["D1"]="http://172.30.0.172:9090,1,2"
hashmap["D2"]="http://172.30.0.131:9090,3,2"
export TZ='Europe/London'
timeslice=`date +"%Y-%m-%dT%H:%M:%S"`
for key in ${!hashmap[@]}; do
#echo $key;
#echo "${hashmap["$key"]}"
IFS=',' # comma (,) is set as delimiter
read -ra ARR <<< "${hashmap["$key"]}"
dbmarlin_host="${ARR[0]}"
instance_id="${ARR[1]}"
event_type_id="${ARR[2]}"
url=$dbmarlin_host/archiver/rest/v1/event
echo "$key - POST to $url"
post_data="[
{
\"eventId\": 1,
\"startDateTime\": \"$timeslice\",
\"databaseTargetId\": $instance_id,
\"eventTypeId\": $event_type_id,
\"title\": \"Jenkins Deploy $JOB_NAME build $BUILD_NUMBER\",
\"colourCode\": \"#6c757d\",
\"description\": \"Jenkins Deployed build $BUILD_NUMBER\",
\"detailsUrl\": \"$BUILD_URL\",
\"endDateTime\": null
}
]"
echo "$post_data"
curl --location --request POST $url --header 'Content-Type: application/json' -d "$post_data"
echo ""
done

The code above makes a POST request to [dbmarlin_host]/archiver/rest/v1/event with post_data containing the parameters you want to send.

POST ParamDescription
eventIdEvent ID is not required
startDateTimeAn ISO date which we set based on the output from date +"%Y-%m-%dT%H:%M:%S". Note that we also export TZ='Europe/London' in the script since our Jenkins server is running on UTC and we want to covert it to Europe/London timezone.
databaseTargetIdThe database target ID can be found from the browser address bar if you go to the Instance overview screen E.g. For https://play.dbmarlin.com/instances/2/activity the databaseTargetId is 2.
eventTypeIdEvent Type ID can be found in the browser address bar if you go to the Event Types screen and click the Edit button. E.g. for https://play.dbmarlin.com/admin/event-types/edit/2 the eventTypeId is 2
titleThe title of the event. In the example we include Jenkins Deploy $JOB_NAME build $BUILD_NUMBER but could include any text of Jenkins variables
colourCodeA hex colour code.
descriptionThe title of the event. In the example we include Jenkins Deployed build $BUILD_NUMBER but could include any text of Jenkins variables
detailsUrlDefined the hyperlink to use in DBmarlin. Setting to $BUILD_URL will let you link back to the job
detailsUrlDefined the hyperlink to use in DBmarlin. Setting to $BUILD_URL will let you link back to the specific build of the job
endDateTimeNot required for point in time events. Set to null.

Linking from DBmarlin to Jenkins

As long as you send the $BUILD_URL as the detailsUrl in the request to the DBmarlin events API there will be a hyperlink back to the Jenkins job from inside DBmarlin.

https://d33wubrfki0l68.cloudfront.net/da74f44d73a2f714f516bc2912b676fe7867daa0/6a210/img/dbmarlin-link-to-jenkins.png

Above you can see build 602 created a performance spike in the database. You can then decide whether to roll back the new build or fix the problem and continue.