Skip to content

Commit 5ecc84d

Browse files
committed
Add Jenkinsfile for container image building and pushing to DockerHub
1 parent f0f9cc5 commit 5ecc84d

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Jenkinsfile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
void setBuildStatus(String message, String state) {
2+
step([
3+
$class: "GitHubCommitStatusSetter",
4+
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "${env.GIT_URL}"],
5+
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "ci/docker/dataverse-sample-data"],
6+
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
7+
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
8+
]);
9+
}
10+
11+
pipeline {
12+
agent any
13+
environment {
14+
dockerfile = "./Dockerfile"
15+
context = "."
16+
imagetag = "build-${env.BUILD_ID}"
17+
hublogin = "dockerhub-dataversebot"
18+
registry = "https://registry.hub.docker.com"
19+
}
20+
environment {
21+
DOCKER_IMAGE_NAME = "iqss/dataverse-sample-data"
22+
DOCKER_IMAGE_TAG = "build-${env.BRANCH_NAME}"
23+
DOCKER_WORKDIR = "."
24+
DOCKER_HUB_CRED = "dockerhub-dataversebot"
25+
DOCKER_REGISTRY = "https://registry.hub.docker.com"
26+
}
27+
stages {
28+
stage('build') {
29+
when {
30+
anyOf {
31+
branch 'master'
32+
branch '13-dockerize'
33+
}
34+
}
35+
steps {
36+
script {
37+
docker_image = docker.build("${env.DOCKER_IMAGE_NAME}:${env.DOCKER_IMAGE_TAG}", "--pull ${env.DOCKER_WORKDIR}")
38+
}
39+
}
40+
}
41+
stage('push') {
42+
when {
43+
anyOf {
44+
branch 'master'
45+
branch '13-dockerize'
46+
}
47+
}
48+
steps {
49+
script {
50+
// Push master image to latest tag
51+
docker.withRegistry("${env.DOCKER_REGISTRY}", "${env.DOCKER_HUB_CRED}") {
52+
docker_image.push("latest")
53+
}
54+
}
55+
}
56+
}
57+
}
58+
post {
59+
success {
60+
setBuildStatus("Image build and push succeeded", "SUCCESS");
61+
}
62+
failure {
63+
setBuildStatus("Image build or push failed", "FAILURE");
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)