pep-container-image/Jenkinsfile

67 lines
2.0 KiB
Plaintext
Raw Normal View History

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 {
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 {
// 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 {
docker.withRegistry( registryUrl, registryCredential ) {
2024-05-07 14:17:24 +02:00
dockerImage.push("$BUILD_NUMBER")
dockerImage.push('latest')
2024-05-07 14:17:24 +02:00
}
}
}
}
stage('Remove Unused docker image') {
steps{
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}"
}
}
}