2024-05-07 14:17:24 +02:00
|
|
|
// 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 {
|
2024-05-07 18:48:37 +02:00
|
|
|
imagename = "pep/nginx-pep"
|
|
|
|
hubname = "hub.dev.d4science.org"
|
|
|
|
registryUrl = "https://hub.dev.d4science.org"
|
|
|
|
registryCredential = 'c4ece6a2-3488-43c4-b74d-714b057845d1'
|
|
|
|
dockerImage = ''
|
|
|
|
git_url='https://code-repo.d4science.org/D4Science/pep-container-image.git'
|
2024-05-07 14:17:24 +02:00
|
|
|
}
|
|
|
|
stages {
|
2024-05-07 18:48:37 +02:00
|
|
|
// stage('Cloning Git') {
|
|
|
|
// steps {
|
|
|
|
// git([url: git_url, branch: 'main', credentialsId: ''])
|
|
|
|
// }
|
|
|
|
// }
|
2024-05-07 14:17:24 +02:00
|
|
|
stage('Building image') {
|
|
|
|
steps{
|
|
|
|
script {
|
|
|
|
dockerImage = docker.build imagename
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Deploy Image') {
|
|
|
|
steps{
|
|
|
|
script {
|
2024-05-07 18:48:37 +02:00
|
|
|
docker.withRegistry( registryUrl, registryCredential ) {
|
2024-05-07 14:17:24 +02:00
|
|
|
dockerImage.push("$BUILD_NUMBER")
|
2024-05-07 18:48:37 +02:00
|
|
|
dockerImage.push('latest')
|
2024-05-07 14:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Remove Unused docker image') {
|
|
|
|
steps{
|
2024-05-07 18:48:37 +02:00
|
|
|
sh "docker rmi $hubname/$imagename:$BUILD_NUMBER"
|
|
|
|
sh "docker rmi $hubname/$imagename:latest"
|
2024-05-07 14:17:24 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// post-build actions
|
|
|
|
post {
|
|
|
|
success {
|
|
|
|
echo 'The docker pipeline worked!'
|
|
|
|
emailext to: 'jenkinsbuilds@d4science.org',
|
|
|
|
subject: "[Jenkins DockerPipeline D4S] 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: "[Jenkins DockerPipeline D4S] build ${currentBuild.fullDisplayName} failed for image ${imagename}",
|
|
|
|
body: "Something is wrong with ${env.BUILD_URL}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|