|
@@ -89,32 +89,46 @@ pipeline {
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
- stage('Docker Registry Login, Pull, and Push') {
|
|
|
|
|
- when {
|
|
|
|
|
- branch 'master'
|
|
|
|
|
- }
|
|
|
|
|
- steps {
|
|
|
|
|
- script {
|
|
|
|
|
- def imageName = 'sonarqube'
|
|
|
|
|
- def registryUrl = 'nexus.foodgame.fr:8123'
|
|
|
|
|
-
|
|
|
|
|
- docker.withRegistry("https://${registryUrl}", 'nexus') {
|
|
|
|
|
- try {
|
|
|
|
|
- docker.image("${registryUrl}/${imageName}:latest").pull()
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- echo "Image pull failed. Attempting to build and push."
|
|
|
|
|
-
|
|
|
|
|
- // Build image
|
|
|
|
|
- def customImage = docker.build("${imageName}")
|
|
|
|
|
|
|
+ pipeline {
|
|
|
|
|
+ agent any
|
|
|
|
|
+ stages {
|
|
|
|
|
+ stage('Docker Registry Login, Pull, and Push') {
|
|
|
|
|
+ when {
|
|
|
|
|
+ branch 'master'
|
|
|
|
|
+ }
|
|
|
|
|
+ steps {
|
|
|
|
|
+ script {
|
|
|
|
|
+ def registryUrl = 'nexus.foodgame.fr:8123'
|
|
|
|
|
+ def imageName = 'sonarqube'
|
|
|
|
|
+ def imageVersion = 'latest'
|
|
|
|
|
|
|
|
- // Tag and push
|
|
|
|
|
- customImage.tag("${registryUrl}/${imageName}:latest")
|
|
|
|
|
- customImage.push()
|
|
|
|
|
|
|
+ docker.withRegistry("https://${registryUrl}", 'nexus') {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // Try pulling the image from the registry
|
|
|
|
|
+ echo "Trying to pull image: ${registryUrl}/${imageName}:${imageVersion}"
|
|
|
|
|
+ docker.image("${registryUrl}/${imageName}:${imageVersion}").pull()
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ echo "Image pull failed. Attempting to build and push."
|
|
|
|
|
+
|
|
|
|
|
+ // Pull base image from Docker Hub
|
|
|
|
|
+ echo "Pulling base image: ${imageName}:${imageVersion}"
|
|
|
|
|
+ sh "docker pull ${imageName}:${imageVersion}"
|
|
|
|
|
+
|
|
|
|
|
+ // Tag the image for the private registry
|
|
|
|
|
+ echo "Tagging image for private registry"
|
|
|
|
|
+ sh "docker tag ${imageName}:${imageVersion} ${registryUrl}/${imageName}:${imageVersion}"
|
|
|
|
|
+
|
|
|
|
|
+ // Push the tagged image to the private registry
|
|
|
|
|
+ echo "Pushing image to private registry"
|
|
|
|
|
+ sh "docker push ${registryUrl}/${imageName}:${imageVersion}"
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
stage('Cleanup') {
|
|
stage('Cleanup') {
|
|
|
steps {
|
|
steps {
|
|
|
echo "Nettoyage terminé pour la branche ${env.BRANCH_NAME}"
|
|
echo "Nettoyage terminé pour la branche ${env.BRANCH_NAME}"
|