From ed087f1489c400bfb5291743c75462d9aaacc37c Mon Sep 17 00:00:00 2001 From: Westy21 Date: Wed, 29 Nov 2023 16:06:06 +0200 Subject: [PATCH 1/3] updated jenkinsfile to use the derinpope implementation --- Jenkinsfile | 62 +++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9d4e452..3be1a62 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,39 +1,31 @@ pipeline { - environment { - registry = 'https://index.docker.io/v1/' - registryCredential = 'Docker_ID' - name = 'react-todo-app' - dockerImage = '' + agent { label 'linux' } + options { + buildDiscarder(logRotator(numToKeepStr: '5')) + } + environment { + DOCKERHUB_CREDENTIALS = credentials('Docker_ID') + } + stages { + stage('Build') { + steps { + sh 'docker build -t westy22/react-todo:latest .' + } } - - agent any - - stages { - stage('Build Docker Image') { - steps { - script { - // Your Docker build steps go here - docker.build("${name}:${BUILD_NUMBER}") - } - } - } - - stage('Deploy Docker Image') { - steps { - script { - // Use Docker Hub credentials directly for authentication - withDockerRegistry([credentialsId: "${registryCredential}", url: "${registry}"]) { - // Docker push steps - docker.image("${name}:${BUILD_NUMBER}").push() - } - } - } - } - - stage('Cleaning up') { - steps { - sh "docker rmi ${name}:${BUILD_NUMBER}" - } - } + stage('Login') { + steps { + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' + } } + stage('Push') { + steps { + sh 'docker push westy22/react-todo:latest' + } + } + } + post { + always { + sh 'docker logout' + } + } } From 73ffaa346c42b39550ee7633d7189e99592a72b2 Mon Sep 17 00:00:00 2001 From: Westy21 Date: Wed, 29 Nov 2023 16:11:45 +0200 Subject: [PATCH 2/3] updated jenkinsfile set agent to any --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3be1a62..91b245a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,7 @@ pipeline { - agent { label 'linux' } + + agent any + options { buildDiscarder(logRotator(numToKeepStr: '5')) } From f71b1ccf800c32fb32eeb55049837e4a46366b83 Mon Sep 17 00:00:00 2001 From: Westy21 Date: Wed, 29 Nov 2023 16:19:14 +0200 Subject: [PATCH 3/3] updated jenkinsfile docker tagname --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 91b245a..353d469 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { stages { stage('Build') { steps { - sh 'docker build -t westy22/react-todo:latest .' + sh 'docker build -t westy22/westy-docker-hub:raect-todo-latest .' } } stage('Login') { @@ -21,7 +21,7 @@ pipeline { } stage('Push') { steps { - sh 'docker push westy22/react-todo:latest' + sh 'docker push westy22/westy-docker-hub:raect-todo-latest' } } }