feature/24899 #1

Merged
ahmed.ibrahim39699 merged 6 commits from feature/24899 into main 2023-04-03 14:03:08 +02:00
1 changed files with 67 additions and 0 deletions

67
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,67 @@
pipeline {
agent {
label 'docker'
}
environment {
imagename = "d4science/janetbackend" //TO FILL WITH THE RIGHT VALUE (RepositoryName) e.g. d4science/RepositoryName
registryCredential = 'e348bfab-5580-4db6-b0e0-d854966bde08'
dockerImage = ''
git_url='https://code-repo.d4science.org/ahmed.ibrahim39699/JanetBackEnd.git' // SET HERE THE URL OF YOUR NEW GIT PROJECT
}
stages {
stage('Cloning Git') {
steps {
git([url: git_url, branch: 'main', credentialsId: '88b54962-1c0e-49cb-8155-22276860f346'])
}
}
stage('Building image') {
steps{
script {
dockerImage = docker.build imagename
}
}
}
stage('Deploy Image') {
steps{
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push("$BUILD_NUMBER")
dockerImage.push('latest')
}
}
}
post {
success {
sh 'echo triggering the portainer service webhook'
sh 'curl -X POST https://portainer.d4science.org/api/webhooks/7912a372-ce48-4931-b85e-28694c93b1e8'
}
}
}
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}"
}
}
}