Integration with CI (Jenkins)
In this article we briefly describe how to use DBpedia Databus with continuous integration systems like Jenkins and provide several examples of jenkins pipelines.
Publishing your data files (datasets) into Databus.
You can use CI tools for publishing metadata of your data into Databus. Here is an example of jenkins pipeline for that:
// databus DataID template for publishing (this is a minimal version)
// here we are publishing only one file
def req(downloadUrl, username, artifact, version, licenseUrl){
return """{
"@context": "https://downloads.dbpedia.org/databus/context.jsonld",
"@graph": [
{
"@type": "Version",
"@id": "https://databus.dbpedia.org/${username}/jenkins/${artifact}/${version}",
"hasVersion": "${version}",
"title": "Test jenkins",
"description": "Test jenkins",
"license": "${licenseUrl}",
"distribution": [
{
"@type": "Part",
"formatExtension": "txt",
"compression": "none",
"downloadURL": "${downloadUrl}"
}
]
}
]
}"""
}
pipeline {
agent any
stages {
stage("Generate data"){
steps{
// we create file for demonstration purpose
script {
sh "echo 'Hello World!' > 'jenkins-test-file-${BUILD_DATE}-${BUILD_NUMBER}.txt'"
}
}
}
// we transfer the file to a nginx www location, the file gets downloadable.
stage('SSH transfer') {
steps([$class: 'BapSshPromotionPublisherPlugin']) {
sshPublisher(
continueOnError: false, failOnError: true,
publishers: [
sshPublisherDesc(
configName: "nginx",
verbose: true,
transfers: [
sshTransfer(sourceFiles: "*.txt", remoteDirectory: "jenkins-test/${BUILD_DATE}")
]
)
]
)
}
}
// we publish the file to databus specifying its download link
stage("Publish to Databus"){
steps{
script{
// USERNAME is your Databus username
withCredentials([usernamePassword(credentialsId: 'DBUS-Kikiriki', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]){
def body = req(
// download uri
"http://test.dbpedia.org/data/jenkins-test/${BUILD_DATE}/jenkins-test-file-${BUILD_DATE}-${BUILD_NUMBER}.txt",
// your Databus username
USERNAME,
"jenkins",
// you specify this as a Databus version
"${BUILD_DATE}-${BUILD_NUMBER}",
"https://dalicc.net/licenselibrary/Apache-2.0"
)
echo """DataID:
${body}"""
def response = httpRequest validResponseCodes: "200",
consoleLogResponseBody: true,
httpMode: 'POST', quiet: true,
requestBody: body,
url: "https://databus.dbpedia.org/api/publish",
customHeaders:[
// here is you Databus Api Key
[name:'X-API-KEY', value: PASSWORD],
[name: "Content-Type", value: "application/ld+json"]
]
echo "Status: ${response.content}"
}
}
}
}
}
}Downloading data files (datasets) from Databus.
Here is a sample script of how to download the latest version of an artifact from Databus in a jenkins pipeline:
Last updated