Skip to content

Commit

Permalink
Add Jenkinsfile for container image building and pushing to DockerHub
Browse files Browse the repository at this point in the history
  • Loading branch information
poikilotherm committed Feb 6, 2020
1 parent f0f9cc5 commit 8d13e95
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
void setBuildStatus(String message, String state) {
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "${env.GIT_URL}"],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/docker/dataverse-sample-data"],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
]);
}

pipeline {
agent any
environment {
DOCKER_IMAGE_NAME = "iqss/dataverse-sample-data"
DOCKER_IMAGE_TAG = "build-${env.BRANCH_NAME}"
DOCKER_WORKDIR = "."
DOCKER_HUB_CRED = "dockerhub-dataversebot"
DOCKER_REGISTRY = "https://registry.hub.docker.com"
}
stages {
stage('build') {
when {
anyOf {
branch 'master'
branch '13-dockerize'
}
}
steps {
script {
docker_image = docker.build("${env.DOCKER_IMAGE_NAME}:${env.DOCKER_IMAGE_TAG}", "--pull ${env.DOCKER_WORKDIR}")
}
}
}
stage('push') {
when {
anyOf {
branch 'master'
branch '13-dockerize'
}
}
steps {
script {
// Push master image to latest tag
docker.withRegistry("${env.DOCKER_REGISTRY}", "${env.DOCKER_HUB_CRED}") {
docker_image.push("latest")
}
}
}
}
}
post {
success {
setBuildStatus("Image build and push succeeded", "SUCCESS");
}
failure {
setBuildStatus("Image build or push failed", "FAILURE");
}
}
}

0 comments on commit 8d13e95

Please sign in to comment.