62 lines
1.9 KiB
Groovy
62 lines
1.9 KiB
Groovy
// REMEMBER TO FILL THE environment section with your values.
|
|
// the following filed should be filled: imagename, git_url
|
|
// REMEMBER to put your Dockerfile in the root folder of your project
|
|
// The related jenkinsjob template is here:
|
|
|
|
|
|
pipeline {
|
|
agent {
|
|
label 'docker'
|
|
}
|
|
environment {
|
|
imagename = "external-services/ckan-2-6-bluecloud"
|
|
hubname = "harbor.d4science.org"
|
|
registryUrl = "https://harbor.d4science.org"
|
|
registryCredential = 'harbor-ckan-legacy'
|
|
dockerImage = ''
|
|
git_url='https://code-repo.d4science.org/D4Science/ckan-2-6-legacy.git'
|
|
}
|
|
stages {
|
|
stage('Building image') {
|
|
steps{
|
|
script {
|
|
dockerImage = docker.build imagename
|
|
}
|
|
}
|
|
}
|
|
stage('Deploy Image') {
|
|
steps{
|
|
script {
|
|
docker.withRegistry( registryUrl, registryCredential ) {
|
|
dockerImage.push("$BUILD_NUMBER")
|
|
dockerImage.push('latest')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage('Remove Unused docker image') {
|
|
steps{
|
|
sh "docker rmi $hubname/$imagename:$BUILD_NUMBER"
|
|
sh "docker rmi $hubname/$imagename:latest"
|
|
|
|
}
|
|
}
|
|
}
|
|
// post-build actions
|
|
post {
|
|
success {
|
|
echo 'The docker pipeline worked!'
|
|
emailext to: 'jenkinsbuilds@d4science.org',
|
|
subject: "[Jenkins CKAN legacy] build ${currentBuild.fullDisplayName} worked",
|
|
body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}"
|
|
}
|
|
failure {
|
|
echo 'The docker pipeline has failed'
|
|
emailext attachLog: true,
|
|
to: 'jenkinsbuilds@d4science.org',
|
|
subject: "[FAILURE: Jenkins CKAN legacy] build ${currentBuild.fullDisplayName} failed for image ${imagename}",
|
|
body: "Something is wrong with ${env.BUILD_URL}"
|
|
}
|
|
}
|
|
}
|