From 2982ad37188d1b2329625a82d0dfb8f16cf43413 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik Date: Mon, 4 Sep 2023 11:11:34 +0100 Subject: [PATCH 01/38] Add NGINX - pipeline.groovy --- NGINX - pipeline.groovy | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 NGINX - pipeline.groovy diff --git a/NGINX - pipeline.groovy b/NGINX - pipeline.groovy new file mode 100644 index 00000000..f5caf934 --- /dev/null +++ b/NGINX - pipeline.groovy @@ -0,0 +1,29 @@ +pipeline { + agent any + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Build Docker Image') { + steps { + script { + def dockerImage = docker.build('OnurOzcelikSE/NGINX-Demos', './nginx-hello') + } + } + } + + stage('Push Docker Image') { + steps { + script { + docker.withRegistry('https://index.docker.io/v1/', 'onurozcelikse') { + dockerImage.push() + } + } + } + } + } +} From f1941c9b63582313fbdccf2e19b77b7182d1f330 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Mon, 4 Sep 2023 11:33:06 +0100 Subject: [PATCH 02/38] Update Docker Hub username Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- NGINX - pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NGINX - pipeline.groovy b/NGINX - pipeline.groovy index f5caf934..20f76d36 100644 --- a/NGINX - pipeline.groovy +++ b/NGINX - pipeline.groovy @@ -11,7 +11,7 @@ pipeline { stage('Build Docker Image') { steps { script { - def dockerImage = docker.build('OnurOzcelikSE/NGINX-Demos', './nginx-hello') + def dockerImage = docker.build('onurozcelikse/NGINX-Demos', './nginx-hello') } } } From 91b792a50592bbe49d338e9750fdae562ab3f9db Mon Sep 17 00:00:00 2001 From: Onur Ozcelik Date: Thu, 7 Sep 2023 03:03:42 +0100 Subject: [PATCH 03/38] Update NGINX - pipeline.groovy --- NGINX - pipeline.groovy | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/NGINX - pipeline.groovy b/NGINX - pipeline.groovy index f5caf934..bed9ba13 100644 --- a/NGINX - pipeline.groovy +++ b/NGINX - pipeline.groovy @@ -1,17 +1,35 @@ pipeline { agent any + environment { + DOCKERHUB_CREDENTIALS = credentials('docker-hub-credentials') + } + stages { - stage('Checkout') { + stage('Clone Repository') { steps { - checkout scm + checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/OnurOzcelikSE/NGINX-Demos.git']]]) + echo 'Repository cloned' } } - stage('Build Docker Image') { steps { script { - def dockerImage = docker.build('OnurOzcelikSE/NGINX-Demos', './nginx-hello') + def registryCredentials = [ + usernamePassword( + credentialsId: 'DOCKERHUB_CREDENTIALS.id', + usernameVariable: 'DOCKERHUB_USERNAME', + passwordVariable: 'DOCKERHUB_PASSWORD' + ) + ] + echo 'Logged in to DockerHub' + + docker.withRegistry('https://hub.docker.com', registryCredentials) { + def imageName = "onurozcelikse/nginx-hello" + def dockerImage = docker.build(imageName) + dockerImage.push() + echo 'Docker image builded' + } } } } @@ -19,11 +37,15 @@ pipeline { stage('Push Docker Image') { steps { script { - docker.withRegistry('https://index.docker.io/v1/', 'onurozcelikse') { - dockerImage.push() - } + docker.withRegistry('https://index.docker.io/v1/', 'onurozcelikse') + echo 'Docker Image Pushed' } } } + stage('Analyze Docker Image') { + steps { + sh 'dive --ci onurozcelikse/nginx-hello --exit-code' + } + } } -} +} \ No newline at end of file From 6551f4fa3d2361c5fd3d9887e38d8990f4a00c09 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik Date: Thu, 7 Sep 2023 03:16:05 +0100 Subject: [PATCH 04/38] Update NGINX - pipeline.groovy --- NGINX - pipeline.groovy => nginx_pipeline.groovy | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename NGINX - pipeline.groovy => nginx_pipeline.groovy (100%) diff --git a/NGINX - pipeline.groovy b/nginx_pipeline.groovy similarity index 100% rename from NGINX - pipeline.groovy rename to nginx_pipeline.groovy From 3ac35d55992acdfedcd3ec9ce085ac0eea69e101 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik Date: Thu, 7 Sep 2023 11:21:12 +0100 Subject: [PATCH 05/38] Update NGINX - pipeline.groovy --- nginx_pipeline.groovy | 96 ++++++++++++++++++++++++++++++++----------- 1 file changed, 71 insertions(+), 25 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index b6b8dc2e..3e389afc 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -2,38 +2,27 @@ pipeline { agent any environment { - DOCKERHUB_CREDENTIALS = credentials('docker-hub-credentials') + DOCKER_REPOSITORY = 'OnurOzcelikSE/NGINX-Demos' } stages { stage('Clone Repository') { steps { - checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/OnurOzcelikSE/NGINX-Demos.git']]]) + checkout([$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[url: 'https://github.com/OnurOzcelikSE/NGINX-Demos.git']]]) echo 'Repository cloned' } } stage('Build Docker Image') { steps { script { -<<<<<<< HEAD - def registryCredentials = [ - usernamePassword( - credentialsId: 'DOCKERHUB_CREDENTIALS.id', - usernameVariable: 'DOCKERHUB_USERNAME', - passwordVariable: 'DOCKERHUB_PASSWORD' - ) - ] - echo 'Logged in to DockerHub' - - docker.withRegistry('https://hub.docker.com', registryCredentials) { - def imageName = "onurozcelikse/nginx-hello" - def dockerImage = docker.build(imageName) - dockerImage.push() - echo 'Docker image builded' + def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + withCredentials([(credentialsId: 'DOCKER_REGISTRY_CREDENTIALS', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD)']) { + sh "docker login --username ${DOCKER_USERNAME} --password ${DOCKER_PASSWORD} docker.io" + echo 'Logged in to DockerHub' + + sh "docker build -t ${dockerImageTag} ./nginx-hello" + echo 'Docker image builded' } -======= - def dockerImage = docker.build('onurozcelikse/NGINX-Demos', './nginx-hello') ->>>>>>> f1941c9b63582313fbdccf2e19b77b7182d1f330 } } } @@ -41,15 +30,72 @@ pipeline { stage('Push Docker Image') { steps { script { - docker.withRegistry('https://index.docker.io/v1/', 'onurozcelikse') - echo 'Docker Image Pushed' + sh "docker push ${dockerImageTag}" + echo 'Docker image pushed' + } + } + } + + stage('Clean Up') { + steps { + script{ + def imageName = ${DOCKER_REPOSITORY}:${env.BUILD_NUMBER} + sh "rm -f ${imageName}" + echo 'Cleanup completed' + } + } + } + + stage('Trigger Next Pipeline') { + steps { + script { + build job: 'docker-image' } } } - stage('Analyze Docker Image') { + } +} + +pipeline { + agent any + + environment { + DOCKER_REPOSITORY = 'OnurOzcelikSE/NGINX-Demos' + LOWEST_EFFICIENCY = '0.7' + HIGHES_USER_WASTED_PERCENT= '0.2' + HIGHEST_WASTED_YTS = '100000000' + } + + parameters { + string(name: 'BUILD_NUMBER', description: 'Build number from the previous pipeline') + } + + stages { + stage ('Pull Docker Image') { steps { - sh 'dive --ci onurozcelikse/nginx-hello --exit-code' + script { + def buildNumber = params.BUILD_NUMBER + def taggedImage = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + sh "docker pull ${taggedImage}" + } + } + } + + stage('Analyze Tagged Docker Image with Dive'){ + steps { + script { + def diveCommand = "dive --ci --lowestEfficiency ${LOWEST_EFFICIENCY} --highestUserWastedPercent ${HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${HIGHEST_WASTED_BYTES} ${taggedImage}" + + def status = sh(script: diveCommand, returnStatus: true) + + if (status == 0) { + echo "Dive analysis completed successfully for ${taggedImage}." + } + else { + error("Dive found inefficiencies in the ${taggedImage} Docker image.") + } + } } } } -} \ No newline at end of file +} From 832bf4c861a5013e84ade8f80730c6006dbd27a9 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 11:54:12 +0100 Subject: [PATCH 06/38] Update nginx_pipeline.groovy Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 49 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 3e389afc..0a6a4383 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -15,13 +15,13 @@ pipeline { stage('Build Docker Image') { steps { script { - def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" - withCredentials([(credentialsId: 'DOCKER_REGISTRY_CREDENTIALS', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD)']) { + def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + withCredentials([usernamePassword(credentialsId: 'DOCKER_HUB_CREDENTIALS', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { sh "docker login --username ${DOCKER_USERNAME} --password ${DOCKER_PASSWORD} docker.io" echo 'Logged in to DockerHub' sh "docker build -t ${dockerImageTag} ./nginx-hello" - echo 'Docker image builded' + echo 'Docker image built' } } } @@ -30,6 +30,7 @@ pipeline { stage('Push Docker Image') { steps { script { + def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" sh "docker push ${dockerImageTag}" echo 'Docker image pushed' } @@ -38,9 +39,9 @@ pipeline { stage('Clean Up') { steps { - script{ - def imageName = ${DOCKER_REPOSITORY}:${env.BUILD_NUMBER} - sh "rm -f ${imageName}" + script { + def imageName = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + sh "docker rmi ${imageName}" echo 'Cleanup completed' } } @@ -48,22 +49,21 @@ pipeline { stage('Trigger Next Pipeline') { steps { - script { - build job: 'docker-image' - } + build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: env.BUILD_NUMBER)] } } } } + pipeline { agent any environment { DOCKER_REPOSITORY = 'OnurOzcelikSE/NGINX-Demos' LOWEST_EFFICIENCY = '0.7' - HIGHES_USER_WASTED_PERCENT= '0.2' - HIGHEST_WASTED_YTS = '100000000' + HIGHEST_USER_WASTED_PERCENT = '0.2' + HIGHEST_WASTED_BYTES = '100000000' } parameters { @@ -71,29 +71,28 @@ pipeline { } stages { - stage ('Pull Docker Image') { + stage('Pull Docker Image') { steps { script { def buildNumber = params.BUILD_NUMBER - def taggedImage = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + def taggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" sh "docker pull ${taggedImage}" } } } - - stage('Analyze Tagged Docker Image with Dive'){ - steps { - script { - def diveCommand = "dive --ci --lowestEfficiency ${LOWEST_EFFICIENCY} --highestUserWastedPercent ${HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${HIGHEST_WASTED_BYTES} ${taggedImage}" - def status = sh(script: diveCommand, returnStatus: true) + stage('Analyze Tagged Docker Image with Dive') { + steps { + script { + def diveCommand = "dive --ci --lowestEfficiency ${LOWEST_EFFICIENCY} --highestUserWastedPercent ${HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${HIGHEST_WASTED_BYTES} ${taggedImage}" + + def status = sh(script: diveCommand, returnStatus: true) - if (status == 0) { - echo "Dive analysis completed successfully for ${taggedImage}." - } - else { - error("Dive found inefficiencies in the ${taggedImage} Docker image.") - } + if (status == 0) { + echo "Dive analysis completed successfully for ${taggedImage}." + } else { + error("Dive found inefficiencies in the ${taggedImage} Docker image.") + } } } } From a041c71bb1abb3d691435124d8e1e70f4f7035ab Mon Sep 17 00:00:00 2001 From: Onur Ozcelik Date: Thu, 7 Sep 2023 12:15:26 +0100 Subject: [PATCH 07/38] Update NGINX - pipeline.groovy --- nginx_pipeline.groovy | 60 +++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 3e389afc..416a196c 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -15,13 +15,18 @@ pipeline { stage('Build Docker Image') { steps { script { - def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" - withCredentials([(credentialsId: 'DOCKER_REGISTRY_CREDENTIALS', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD)']) { - sh "docker login --username ${DOCKER_USERNAME} --password ${DOCKER_PASSWORD} docker.io" - echo 'Logged in to DockerHub' + def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" - sh "docker build -t ${dockerImageTag} ./nginx-hello" - echo 'Docker image builded' + // Use withCredentials to securely pass Docker Hub credentials + withCredentials([usernamePassword(credentialsId: 'DOCKER_HUB_CREDENTIALS', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { + echo 'Logged in to DockerHub securely' + + // Use --password-stdin to securely pass the password to docker login + sh """ + echo \${DOCKER_PASSWORD} | docker login --username \${DOCKER_USERNAME} --password-stdin docker.io + docker build -t ${dockerImageTag} ./nginx-hello + """ + echo 'Docker image built' } } } @@ -30,6 +35,7 @@ pipeline { stage('Push Docker Image') { steps { script { + def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" sh "docker push ${dockerImageTag}" echo 'Docker image pushed' } @@ -38,9 +44,9 @@ pipeline { stage('Clean Up') { steps { - script{ - def imageName = ${DOCKER_REPOSITORY}:${env.BUILD_NUMBER} - sh "rm -f ${imageName}" + script { + def imageName = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + sh "docker rmi ${imageName}" echo 'Cleanup completed' } } @@ -48,22 +54,21 @@ pipeline { stage('Trigger Next Pipeline') { steps { - script { - build job: 'docker-image' - } + build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: env.BUILD_NUMBER)] } } } } + pipeline { agent any environment { DOCKER_REPOSITORY = 'OnurOzcelikSE/NGINX-Demos' LOWEST_EFFICIENCY = '0.7' - HIGHES_USER_WASTED_PERCENT= '0.2' - HIGHEST_WASTED_YTS = '100000000' + HIGHEST_USER_WASTED_PERCENT = '0.2' + HIGHEST_WASTED_BYTES = '100000000' } parameters { @@ -71,29 +76,28 @@ pipeline { } stages { - stage ('Pull Docker Image') { + stage('Pull Docker Image') { steps { script { def buildNumber = params.BUILD_NUMBER - def taggedImage = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + def taggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" sh "docker pull ${taggedImage}" } } } - - stage('Analyze Tagged Docker Image with Dive'){ - steps { - script { - def diveCommand = "dive --ci --lowestEfficiency ${LOWEST_EFFICIENCY} --highestUserWastedPercent ${HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${HIGHEST_WASTED_BYTES} ${taggedImage}" - def status = sh(script: diveCommand, returnStatus: true) + stage('Analyze Tagged Docker Image with Dive') { + steps { + script { + def diveCommand = "dive --ci --lowestEfficiency ${LOWEST_EFFICIENCY} --highestUserWastedPercent ${HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${HIGHEST_WASTED_BYTES} ${taggedImage}" - if (status == 0) { - echo "Dive analysis completed successfully for ${taggedImage}." - } - else { - error("Dive found inefficiencies in the ${taggedImage} Docker image.") - } + def status = sh(script: diveCommand, returnStatus: true) + + if (status == 0) { + echo "Dive analysis completed successfully for ${taggedImage}." + } else { + error("Dive found inefficiencies in the ${taggedImage} Docker image.") + } } } } From d1bc62cfc8b8507649117db5739a68612b8db04b Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:16:20 +0100 Subject: [PATCH 08/38] Update nginx_pipeline.groovy Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 0a6a4383..416a196c 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -16,11 +16,16 @@ pipeline { steps { script { def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + + // Use withCredentials to securely pass Docker Hub credentials withCredentials([usernamePassword(credentialsId: 'DOCKER_HUB_CREDENTIALS', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) { - sh "docker login --username ${DOCKER_USERNAME} --password ${DOCKER_PASSWORD} docker.io" - echo 'Logged in to DockerHub' + echo 'Logged in to DockerHub securely' - sh "docker build -t ${dockerImageTag} ./nginx-hello" + // Use --password-stdin to securely pass the password to docker login + sh """ + echo \${DOCKER_PASSWORD} | docker login --username \${DOCKER_USERNAME} --password-stdin docker.io + docker build -t ${dockerImageTag} ./nginx-hello + """ echo 'Docker image built' } } From e246caeeb8fd0ada36d223d8a74419dbe6d9ccb3 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:20:25 +0100 Subject: [PATCH 09/38] Update repository name Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 416a196c..c4257d29 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -65,7 +65,7 @@ pipeline { agent any environment { - DOCKER_REPOSITORY = 'OnurOzcelikSE/NGINX-Demos' + DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' LOWEST_EFFICIENCY = '0.7' HIGHEST_USER_WASTED_PERCENT = '0.2' HIGHEST_WASTED_BYTES = '100000000' From 2f1f2dc0d4acef6ee1f26c423f82f6e905a3f455 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:26:43 +0100 Subject: [PATCH 10/38] Update repository name Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index c4257d29..2e5ad8cd 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -2,7 +2,7 @@ pipeline { agent any environment { - DOCKER_REPOSITORY = 'OnurOzcelikSE/NGINX-Demos' + DOCKER_REPOSITORY = 'onuroOzcelikse/nginx-demos' } stages { From ed14dc2fe348958919b492f89205a104e6090563 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:29:50 +0100 Subject: [PATCH 11/38] Update repository name Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 2e5ad8cd..be326f0c 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -2,7 +2,7 @@ pipeline { agent any environment { - DOCKER_REPOSITORY = 'onuroOzcelikse/nginx-demos' + DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' } stages { From b45dea132eef7867fe6e288226013858e5229b1d Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:50:18 +0100 Subject: [PATCH 12/38] Add Create Pipeline Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index be326f0c..499afa6c 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -52,6 +52,15 @@ pipeline { } } + stage('Create and Run Pipeline') { + steps { + script { + // Load and execute the Jenkinsfile for the new pipeline + load 'docker-dive-pipeline/Jenkinsfile' + } + } + } + stage('Trigger Next Pipeline') { steps { build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: env.BUILD_NUMBER)] From 561163119e1d9ebf9c2e16b614ece56d6cce07a6 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:38:14 +0100 Subject: [PATCH 13/38] Update nginx_pipeline.groovy Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 499afa6c..99360828 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -8,6 +8,7 @@ pipeline { stages { stage('Clone Repository') { steps { + // Checkout the Git repository checkout([$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[url: 'https://github.com/OnurOzcelikSE/NGINX-Demos.git']]]) echo 'Repository cloned' } @@ -15,6 +16,7 @@ pipeline { stage('Build Docker Image') { steps { script { + // Define the Docker image tag def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" // Use withCredentials to securely pass Docker Hub credentials @@ -35,7 +37,10 @@ pipeline { stage('Push Docker Image') { steps { script { + // Define the Docker image tag again def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + + // Push the Docker image sh "docker push ${dockerImageTag}" echo 'Docker image pushed' } @@ -45,39 +50,30 @@ pipeline { stage('Clean Up') { steps { script { + // Define the image name for cleanup def imageName = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" + + // Remove the Docker image sh "docker rmi ${imageName}" echo 'Cleanup completed' } } } - stage('Create and Run Pipeline') { - steps { - script { - // Load and execute the Jenkinsfile for the new pipeline - load 'docker-dive-pipeline/Jenkinsfile' - } - } - } - stage('Trigger Next Pipeline') { steps { + // Trigger the downstream pipeline job and pass the BUILD_NUMBER parameter build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: env.BUILD_NUMBER)] } } } } - pipeline { agent any environment { DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' - LOWEST_EFFICIENCY = '0.7' - HIGHEST_USER_WASTED_PERCENT = '0.2' - HIGHEST_WASTED_BYTES = '100000000' } parameters { @@ -88,8 +84,13 @@ pipeline { stage('Pull Docker Image') { steps { script { + // Get the BUILD_NUMBER parameter def buildNumber = params.BUILD_NUMBER + + // Define the tagged image def taggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" + + // Pull the Docker image sh "docker pull ${taggedImage}" } } @@ -98,8 +99,10 @@ pipeline { stage('Analyze Tagged Docker Image with Dive') { steps { script { - def diveCommand = "dive --ci --lowestEfficiency ${LOWEST_EFFICIENCY} --highestUserWastedPercent ${HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${HIGHEST_WASTED_BYTES} ${taggedImage}" + // Define the Dive command with parameters + def diveCommand = "dive --ci --lowestEfficiency ${env.LOWEST_EFFICIENCY} --highestUserWastedPercent ${env.HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${env.HIGHEST_WASTED_BYTES} ${taggedImage}" + // Execute Dive and capture the status def status = sh(script: diveCommand, returnStatus: true) if (status == 0) { From a8d3d1b885504d70ee7c17f3855dd336ff2ee16d Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:53:12 +0100 Subject: [PATCH 14/38] Update Trigger Stage Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 99360828..394ab282 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -62,8 +62,8 @@ pipeline { stage('Trigger Next Pipeline') { steps { - // Trigger the downstream pipeline job and pass the BUILD_NUMBER parameter - build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: env.BUILD_NUMBER)] + def buildNumberString = env.BUILD_NUMBER.toString() + build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: buildNumberString)] } } } From aee983c2ea86c4edc1f4e91866f641884df5288e Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:57:20 +0100 Subject: [PATCH 15/38] Update Trigger Stage Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 394ab282..aa507082 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -63,7 +63,7 @@ pipeline { stage('Trigger Next Pipeline') { steps { def buildNumberString = env.BUILD_NUMBER.toString() - build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: buildNumberString)] + build job: 'docker-dive-pipeline', parameters: [[$class: 'StringParameterValue', name: 'BUILD_NUMBER', value: buildNumberString]] } } } From 01977b662b650a5959f50dab5ac4e9d01d8e23cd Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:01:04 +0100 Subject: [PATCH 16/38] Update Trigger Stage Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index aa507082..187cb12f 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -62,8 +62,10 @@ pipeline { stage('Trigger Next Pipeline') { steps { - def buildNumberString = env.BUILD_NUMBER.toString() - build job: 'docker-dive-pipeline', parameters: [[$class: 'StringParameterValue', name: 'BUILD_NUMBER', value: buildNumberString]] + script { + def buildNumberString = env.BUILD_NUMBER.toString() + build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: buildNumberString)] + } } } } From fdbd1a44e64d83458a72701a53066819e8e99895 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:28:39 +0100 Subject: [PATCH 17/38] Delete second pipeline Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 47 ------------------------------------------- 1 file changed, 47 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 187cb12f..be64082f 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -70,50 +70,3 @@ pipeline { } } } - -pipeline { - agent any - - environment { - DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' - } - - parameters { - string(name: 'BUILD_NUMBER', description: 'Build number from the previous pipeline') - } - - stages { - stage('Pull Docker Image') { - steps { - script { - // Get the BUILD_NUMBER parameter - def buildNumber = params.BUILD_NUMBER - - // Define the tagged image - def taggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" - - // Pull the Docker image - sh "docker pull ${taggedImage}" - } - } - } - - stage('Analyze Tagged Docker Image with Dive') { - steps { - script { - // Define the Dive command with parameters - def diveCommand = "dive --ci --lowestEfficiency ${env.LOWEST_EFFICIENCY} --highestUserWastedPercent ${env.HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${env.HIGHEST_WASTED_BYTES} ${taggedImage}" - - // Execute Dive and capture the status - def status = sh(script: diveCommand, returnStatus: true) - - if (status == 0) { - echo "Dive analysis completed successfully for ${taggedImage}." - } else { - error("Dive found inefficiencies in the ${taggedImage} Docker image.") - } - } - } - } - } -} From b2bc3fd945f313746dea03a3767fc433693c63fe Mon Sep 17 00:00:00 2001 From: Onur Ozcelik Date: Thu, 7 Sep 2023 14:30:19 +0100 Subject: [PATCH 18/38] Add Docker-dive-pipeline.groovy --- nginx_pipeline.groovy | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 416a196c..47716f25 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -2,7 +2,7 @@ pipeline { agent any environment { - DOCKER_REPOSITORY = 'OnurOzcelikSE/NGINX-Demos' + DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' } stages { @@ -52,9 +52,19 @@ pipeline { } } + stage('Create and Run Pipeline') { + steps { + script { + // Load and execute the Jenkinsfile for the new pipeline + load 'docker-dive-pipeline/Jenkinsfile' + } + } + } + stage('Trigger Next Pipeline') { steps { - build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: env.BUILD_NUMBER)] + def buildNumberString = env.BUILD_NUMBER.toString() + build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: buildNumberString)] } } } @@ -65,7 +75,7 @@ pipeline { agent any environment { - DOCKER_REPOSITORY = 'OnurOzcelikSE/NGINX-Demos' + DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' LOWEST_EFFICIENCY = '0.7' HIGHEST_USER_WASTED_PERCENT = '0.2' HIGHEST_WASTED_BYTES = '100000000' @@ -102,4 +112,4 @@ pipeline { } } } -} +} \ No newline at end of file From 2b9a2119a23ce4aa6986a8085ff0d3f17292faaa Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:38:21 +0100 Subject: [PATCH 19/38] Update nginx_pipeline Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- nginx_pipeline.groovy | 70 +------------------------------------------ 1 file changed, 1 insertion(+), 69 deletions(-) diff --git a/nginx_pipeline.groovy b/nginx_pipeline.groovy index 22907cc8..be64082f 100644 --- a/nginx_pipeline.groovy +++ b/nginx_pipeline.groovy @@ -16,10 +16,7 @@ pipeline { stage('Build Docker Image') { steps { script { -<<<<<<< HEAD -======= // Define the Docker image tag ->>>>>>> fdbd1a44e64d83458a72701a53066819e8e99895 def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" // Use withCredentials to securely pass Docker Hub credentials @@ -40,14 +37,10 @@ pipeline { stage('Push Docker Image') { steps { script { -<<<<<<< HEAD - def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" -======= // Define the Docker image tag again def dockerImageTag = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" // Push the Docker image ->>>>>>> fdbd1a44e64d83458a72701a53066819e8e99895 sh "docker push ${dockerImageTag}" echo 'Docker image pushed' } @@ -57,84 +50,23 @@ pipeline { stage('Clean Up') { steps { script { -<<<<<<< HEAD - def imageName = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" -======= // Define the image name for cleanup def imageName = "${DOCKER_REPOSITORY}:${env.BUILD_NUMBER}" // Remove the Docker image ->>>>>>> fdbd1a44e64d83458a72701a53066819e8e99895 sh "docker rmi ${imageName}" echo 'Cleanup completed' } } } - stage('Create and Run Pipeline') { - steps { - script { - // Load and execute the Jenkinsfile for the new pipeline - load 'docker-dive-pipeline/Jenkinsfile' - } - } - } - stage('Trigger Next Pipeline') { steps { -<<<<<<< HEAD - def buildNumberString = env.BUILD_NUMBER.toString() - build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: buildNumberString)] - } - } - } -} - - -pipeline { - agent any - - environment { - DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' - LOWEST_EFFICIENCY = '0.7' - HIGHEST_USER_WASTED_PERCENT = '0.2' - HIGHEST_WASTED_BYTES = '100000000' - } - - parameters { - string(name: 'BUILD_NUMBER', description: 'Build number from the previous pipeline') - } - - stages { - stage('Pull Docker Image') { - steps { - script { - def buildNumber = params.BUILD_NUMBER - def taggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" - sh "docker pull ${taggedImage}" - } - } - } - - stage('Analyze Tagged Docker Image with Dive') { - steps { - script { - def diveCommand = "dive --ci --lowestEfficiency ${LOWEST_EFFICIENCY} --highestUserWastedPercent ${HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${HIGHEST_WASTED_BYTES} ${taggedImage}" - - def status = sh(script: diveCommand, returnStatus: true) - - if (status == 0) { - echo "Dive analysis completed successfully for ${taggedImage}." - } else { - error("Dive found inefficiencies in the ${taggedImage} Docker image.") - } -======= script { def buildNumberString = env.BUILD_NUMBER.toString() build job: 'docker-dive-pipeline', parameters: [string(name: 'BUILD_NUMBER', value: buildNumberString)] ->>>>>>> fdbd1a44e64d83458a72701a53066819e8e99895 } } } } -} \ No newline at end of file +} From 0bdfe405b483978f93431a5f3e8d300cf33fc624 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:47:39 +0100 Subject: [PATCH 20/38] Add properties Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 18ae6fba..3e1775a4 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -4,6 +4,20 @@ pipeline { environment { DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' } + properties([ + parameters([ + booleanParam( + defaultValue: false, + description: 'isFoo should be false', + name: 'isFoo' + ), + booleanParam( + defaultValue: true, + description: 'isBar should be true', + name: 'isBar' + ), + ]) + ]) parameters { string(name: 'BUILD_NUMBER', description: 'Build number from the previous pipeline') @@ -17,10 +31,10 @@ pipeline { def buildNumber = params.BUILD_NUMBER // Define the tagged image - def taggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" + def dockerTaggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" // Pull the Docker image - sh "docker pull ${taggedImage}" + sh "docker pull ${dockerTaggedImage}" } } } @@ -43,4 +57,4 @@ pipeline { } } } -} \ No newline at end of file +} From a9539e41b7876ff99d77384462778198f8e18b8f Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:51:45 +0100 Subject: [PATCH 21/38] add options Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 3e1775a4..ded46a68 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -4,7 +4,7 @@ pipeline { environment { DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' } - properties([ + options([ parameters([ booleanParam( defaultValue: false, From 74f498f3b3ffebd1bff2774d0f55446b82ede355 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 14:55:51 +0100 Subject: [PATCH 22/38] delete options Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index ded46a68..7e33a933 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -4,20 +4,6 @@ pipeline { environment { DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' } - options([ - parameters([ - booleanParam( - defaultValue: false, - description: 'isFoo should be false', - name: 'isFoo' - ), - booleanParam( - defaultValue: true, - description: 'isBar should be true', - name: 'isBar' - ), - ]) - ]) parameters { string(name: 'BUILD_NUMBER', description: 'Build number from the previous pipeline') From 8b8d51e0138cb2f791c5668a9f18d2b0eebfcd85 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:01:20 +0100 Subject: [PATCH 23/38] Update docker-dive-pipeline.groovy Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 7e33a933..ad8384b0 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -35,9 +35,9 @@ pipeline { def status = sh(script: diveCommand, returnStatus: true) if (status == 0) { - echo "Dive analysis completed successfully for ${taggedImage}." + echo "Dive analysis completed successfully for ${DockerTaggedImage}." } else { - error("Dive found inefficiencies in the ${taggedImage} Docker image.") + error("Dive found inefficiencies in the ${DockerTaggedImage} Docker image.") } } } From 8a1f33116035f5aab1f802c9352d691632d4e4fc Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:03:02 +0100 Subject: [PATCH 24/38] Update docker-dive-pipeline.groovy Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index ad8384b0..a00d6c2b 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -29,7 +29,7 @@ pipeline { steps { script { // Define the Dive command with parameters - def diveCommand = "dive --ci --lowestEfficiency ${env.LOWEST_EFFICIENCY} --highestUserWastedPercent ${env.HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${env.HIGHEST_WASTED_BYTES} ${taggedImage}" + def diveCommand = "dive --ci --lowestEfficiency ${env.LOWEST_EFFICIENCY} --highestUserWastedPercent ${env.HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${env.HIGHEST_WASTED_BYTES} ${DockerTaggedImage}" // Execute Dive and capture the status def status = sh(script: diveCommand, returnStatus: true) From 003fa1c2a8b96e3b841f0dbfb2141e2b3081656e Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:05:08 +0100 Subject: [PATCH 25/38] Update docker-dive-pipeline.groovy Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index a00d6c2b..43b035d4 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -29,15 +29,15 @@ pipeline { steps { script { // Define the Dive command with parameters - def diveCommand = "dive --ci --lowestEfficiency ${env.LOWEST_EFFICIENCY} --highestUserWastedPercent ${env.HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${env.HIGHEST_WASTED_BYTES} ${DockerTaggedImage}" + def diveCommand = "dive --ci --lowestEfficiency ${env.LOWEST_EFFICIENCY} --highestUserWastedPercent ${env.HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${env.HIGHEST_WASTED_BYTES} ${dockerTaggedImage}" // Execute Dive and capture the status def status = sh(script: diveCommand, returnStatus: true) if (status == 0) { - echo "Dive analysis completed successfully for ${DockerTaggedImage}." + echo "Dive analysis completed successfully for ${dockerTaggedImage}." } else { - error("Dive found inefficiencies in the ${DockerTaggedImage} Docker image.") + error("Dive found inefficiencies in the ${dockerTaggedImage} Docker image.") } } } From f6037122e2080a7f3bd82df46900de636eb2b855 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:09:00 +0100 Subject: [PATCH 26/38] add def Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 43b035d4..600ec7b2 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -8,7 +8,9 @@ pipeline { parameters { string(name: 'BUILD_NUMBER', description: 'Build number from the previous pipeline') } - + + def dockerTaggedImage = "" + stages { stage('Pull Docker Image') { steps { From 8b2e5c53ef4c4867cee6258742d36bb7392a10ad Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:10:12 +0100 Subject: [PATCH 27/38] change line Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 600ec7b2..12455cc9 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -9,9 +9,10 @@ pipeline { string(name: 'BUILD_NUMBER', description: 'Build number from the previous pipeline') } - def dockerTaggedImage = "" + stages { + def dockerTaggedImage = "" stage('Pull Docker Image') { steps { script { From 44614b03684aa5b1c0e49199084375bc0b6d3616 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:12:24 +0100 Subject: [PATCH 28/38] Update docker-dive-pipeline.groovy Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 12455cc9..68d86929 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -10,9 +10,7 @@ pipeline { } - stages { - def dockerTaggedImage = "" stage('Pull Docker Image') { steps { script { @@ -31,6 +29,11 @@ pipeline { stage('Analyze Tagged Docker Image with Dive') { steps { script { + // Get the BUILD_NUMBER parameter + def buildNumber = params.BUILD_NUMBER + + // Define the tagged image + def dockerTaggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" // Define the Dive command with parameters def diveCommand = "dive --ci --lowestEfficiency ${env.LOWEST_EFFICIENCY} --highestUserWastedPercent ${env.HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${env.HIGHEST_WASTED_BYTES} ${dockerTaggedImage}" From 33783319ee14be0903cbe37f438883c1a47d2c00 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:15:35 +0100 Subject: [PATCH 29/38] add env Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 68d86929..0bf985c3 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -3,6 +3,9 @@ pipeline { environment { DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' + LOWEST_EFFICIENCY = '0.95' + HIGHEST_USER_WASTED_PERCENT = '20MB' + HIGHEST_WASTED_BYTES = '0.20' } parameters { From 0f78bef48f3f8cb17515cb254ed4788f6524e871 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:20:01 +0100 Subject: [PATCH 30/38] add quotes Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 0bf985c3..c0213ecc 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -38,7 +38,7 @@ pipeline { // Define the tagged image def dockerTaggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" // Define the Dive command with parameters - def diveCommand = "dive --ci --lowestEfficiency ${env.LOWEST_EFFICIENCY} --highestUserWastedPercent ${env.HIGHEST_USER_WASTED_PERCENT} --highestWastedBytes ${env.HIGHEST_WASTED_BYTES} ${dockerTaggedImage}" + def diveCommand = "dive --ci --lowestEfficiency '${env.LOWEST_EFFICIENCY}' --highestUserWastedPercent '${env.HIGHEST_USER_WASTED_PERCENT}' --highestWastedBytes '${env.HIGHEST_WASTED_BYTES}' ${dockerTaggedImage}" // Execute Dive and capture the status def status = sh(script: diveCommand, returnStatus: true) From a073b67d03b91304ea22c0e456a97f9657237acd Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:22:34 +0100 Subject: [PATCH 31/38] add \" Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index c0213ecc..2685c874 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -38,7 +38,7 @@ pipeline { // Define the tagged image def dockerTaggedImage = "${DOCKER_REPOSITORY}:${buildNumber}" // Define the Dive command with parameters - def diveCommand = "dive --ci --lowestEfficiency '${env.LOWEST_EFFICIENCY}' --highestUserWastedPercent '${env.HIGHEST_USER_WASTED_PERCENT}' --highestWastedBytes '${env.HIGHEST_WASTED_BYTES}' ${dockerTaggedImage}" + def diveCommand = "dive --ci --lowestEfficiency \"${env.LOWEST_EFFICIENCY}\" --highestUserWastedPercent \"${env.HIGHEST_USER_WASTED_PERCENT}\" --highestWastedBytes \"${env.HIGHEST_WASTED_BYTES}\" ${dockerTaggedImage}" // Execute Dive and capture the status def status = sh(script: diveCommand, returnStatus: true) From 79872971b96c85e15dbe5104e6f821b4896eec3a Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:23:53 +0100 Subject: [PATCH 32/38] Update docker-dive-pipeline.groovy Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 2685c874..433558de 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -4,8 +4,8 @@ pipeline { environment { DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' LOWEST_EFFICIENCY = '0.95' - HIGHEST_USER_WASTED_PERCENT = '20MB' - HIGHEST_WASTED_BYTES = '0.20' + HIGHEST_USER_WASTED_PERCENT = '0.20' + HIGHEST_WASTED_BYTES = '20MB' } parameters { From 4ce0b05d73dc7117061cb410aa7c78db10b2ee9f Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Fri, 8 Sep 2023 08:37:35 +0100 Subject: [PATCH 33/38] Update parameters to fail Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 433558de..529a07e0 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -3,9 +3,9 @@ pipeline { environment { DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' - LOWEST_EFFICIENCY = '0.95' - HIGHEST_USER_WASTED_PERCENT = '0.20' - HIGHEST_WASTED_BYTES = '20MB' + LOWEST_EFFICIENCY = '3.95' + HIGHEST_USER_WASTED_PERCENT = '0.10' + HIGHEST_WASTED_BYTES = '10MB' } parameters { From 73183bf8cf433a131778faf81f92f0e1b8478a1b Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:16:21 +0100 Subject: [PATCH 34/38] Update parameter values back to default and print the values Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 529a07e0..7c57e5af 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -3,9 +3,9 @@ pipeline { environment { DOCKER_REPOSITORY = 'onurozcelikse/nginx-demos' - LOWEST_EFFICIENCY = '3.95' - HIGHEST_USER_WASTED_PERCENT = '0.10' - HIGHEST_WASTED_BYTES = '10MB' + LOWEST_EFFICIENCY = '0.95' + HIGHEST_USER_WASTED_PERCENT = '0.20' + HIGHEST_WASTED_BYTES = '20MB' } parameters { @@ -28,6 +28,17 @@ pipeline { } } } + + stage('Print Environment Variables') { + steps { + script { + // Print the values of environment variables + echo "LOWEST_EFFICIENCY: ${env.LOWEST_EFFICIENCY}" + echo "HIGHEST_USER_WASTED_PERCENT: ${env.HIGHEST_USER_WASTED_PERCENT}" + echo "HIGHEST_WASTED_BYTES: ${env.HIGHEST_WASTED_BYTES}" + } + } + } stage('Analyze Tagged Docker Image with Dive') { steps { From cd1f2b4dfd8bdcac27d7f58d95fc21d470108083 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:21:01 +0100 Subject: [PATCH 35/38] Update Stage Order Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 7c57e5af..98090d69 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -29,17 +29,6 @@ pipeline { } } - stage('Print Environment Variables') { - steps { - script { - // Print the values of environment variables - echo "LOWEST_EFFICIENCY: ${env.LOWEST_EFFICIENCY}" - echo "HIGHEST_USER_WASTED_PERCENT: ${env.HIGHEST_USER_WASTED_PERCENT}" - echo "HIGHEST_WASTED_BYTES: ${env.HIGHEST_WASTED_BYTES}" - } - } - } - stage('Analyze Tagged Docker Image with Dive') { steps { script { @@ -61,6 +50,17 @@ pipeline { } } } + } + + stage('Print Environment Variables') { + steps { + script { + // Print the values of environment variables + echo "Lowest Efficiency": ${env.LOWEST_EFFICIENCY}" + echo "Highest User Wasted Percent": ${env.HIGHEST_USER_WASTED_PERCENT}" + echo "Highest Wasted Bytes": ${env.HIGHEST_WASTED_BYTES}" + } + } } } } From 5f61ac74454ce4add689a3229c9970615fa15e9d Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:22:59 +0100 Subject: [PATCH 36/38] Update syntax Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 98090d69..9be6209b 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -56,9 +56,9 @@ pipeline { steps { script { // Print the values of environment variables - echo "Lowest Efficiency": ${env.LOWEST_EFFICIENCY}" - echo "Highest User Wasted Percent": ${env.HIGHEST_USER_WASTED_PERCENT}" - echo "Highest Wasted Bytes": ${env.HIGHEST_WASTED_BYTES}" + echo "Lowest Efficiency: ${env.LOWEST_EFFICIENCY}" + echo "Highest User Wasted Percent: ${env.HIGHEST_USER_WASTED_PERCENT}" + echo "Highest Wasted Bytes: ${env.HIGHEST_WASTED_BYTES}" } } } From 3f98d96f0b2305d0aa4cbb8c9cbf2229ec52ce4a Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:30:32 +0100 Subject: [PATCH 37/38] Update variables Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 9be6209b..567cf1bf 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -55,10 +55,17 @@ pipeline { stage('Print Environment Variables') { steps { script { - // Print the values of environment variables - echo "Lowest Efficiency: ${env.LOWEST_EFFICIENCY}" - echo "Highest User Wasted Percent: ${env.HIGHEST_USER_WASTED_PERCENT}" - echo "Highest Wasted Bytes: ${env.HIGHEST_WASTED_BYTES}" + // Execute Dive and capture the output + def diveOutput = sh(script: diveCommand, returnStdout: true).trim() + + // Parse the Dive output to extract and print the desired values + def efficiency = (diveOutput =~ /efficiency:\s+([\d.]+ %)/)[0][1] + def userWastedPercent = (diveOutput =~ /userWastedPercent:\s+([\d.]+ %)/)[0][1] + def wastedBytes = (diveOutput =~ /wastedBytes:\s+([\d,]+ bytes)/)[0][1] + + echo "Lowest Efficiency: ${efficiency}" + echo "Highest User Wasted Percent: ${userWastedPercent}" + echo "Highest Wasted Bytes: ${wastedBytes}" } } } From 7154e966b670348626d63b467c34b14c39c13947 Mon Sep 17 00:00:00 2001 From: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:34:55 +0100 Subject: [PATCH 38/38] Update merged stages Signed-off-by: Onur Ozcelik <121237247+OnurOzcelikSE@users.noreply.github.com> --- docker-dive-pipeline.groovy | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/docker-dive-pipeline.groovy b/docker-dive-pipeline.groovy index 567cf1bf..49b181f3 100644 --- a/docker-dive-pipeline.groovy +++ b/docker-dive-pipeline.groovy @@ -48,13 +48,7 @@ pipeline { } else { error("Dive found inefficiencies in the ${dockerTaggedImage} Docker image.") } - } - } - } - - stage('Print Environment Variables') { - steps { - script { + // Execute Dive and capture the output def diveOutput = sh(script: diveCommand, returnStdout: true).trim()