2023-03-31 16:05:36 +02:00
|
|
|
pipeline {
|
|
|
|
agent {
|
|
|
|
label 'docker'
|
|
|
|
}
|
|
|
|
environment {
|
2023-03-31 16:48:46 +02:00
|
|
|
imagename = "d4science/janetfrontend" // d4science account on dockerhub
|
2023-03-31 16:05:36 +02:00
|
|
|
registryCredential = 'e348bfab-5580-4db6-b0e0-d854966bde08'
|
2023-08-29 13:37:28 +02:00
|
|
|
dockerImage = ''
|
2023-03-31 16:38:57 +02:00
|
|
|
git_url='https://code-repo.d4science.org/ahmed.ibrahim39699/JanetFrontEnd.git'
|
2023-03-31 16:05:36 +02:00
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Cloning Git') {
|
|
|
|
steps {
|
2023-03-31 16:59:07 +02:00
|
|
|
git([url: git_url, branch: 'main', credentialsId: '88b54962-1c0e-49cb-8155-22276860f346'])
|
2023-03-31 16:05:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Building image') {
|
|
|
|
steps{
|
|
|
|
script {
|
2023-08-30 11:40:27 +02:00
|
|
|
def version_info=sh(script: "git rev-parse --short HEAD", returnStdout: true)
|
|
|
|
dockerImage = docker.build(imagename, '--build-arg version_info=${version_info} .')
|
2023-03-31 16:05:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Deploy Image') {
|
|
|
|
steps{
|
|
|
|
script {
|
|
|
|
docker.withRegistry( '', registryCredential ) {
|
|
|
|
dockerImage.push("$BUILD_NUMBER")
|
|
|
|
dockerImage.push('latest')
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-03 10:15:40 +02:00
|
|
|
post {
|
|
|
|
success {
|
|
|
|
sh 'echo triggering the portainer service webhook'
|
2023-08-22 18:27:39 +02:00
|
|
|
sh 'curl -X POST https://portainer.d4science.org/api/webhooks/d1a20f73-68c4-4853-b2bd-71a297a2327c'
|
2023-04-03 10:15:40 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-31 16:05:36 +02:00
|
|
|
}
|
|
|
|
stage('Remove Unused docker image') {
|
|
|
|
steps{
|
|
|
|
sh "docker rmi $imagename:$BUILD_NUMBER"
|
|
|
|
sh "docker rmi $imagename:latest"
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|