From c5ab23fa724cb65e9c880fa4d8d153924509aded Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 31 Mar 2023 15:30:27 +0200 Subject: [PATCH 1/6] add JenkinsFile --- Jenkinsfile | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..09612b8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,61 @@ +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: 'master', 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') + + } + } + } + } + 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}" + } + } +} + From 75bf6245f9b6142bf038edaaa449bd63d0758154 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 31 Mar 2023 16:41:58 +0200 Subject: [PATCH 2/6] fix branchname --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 09612b8..8163c3d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { stages { stage('Cloning Git') { steps { - git([url: git_url, branch: 'master', credentialsId: '88b54962-1c0e-49cb-8155-22276860f346']) + git([url: git_url, branch: 'feature/24899', credentialsId: '88b54962-1c0e-49cb-8155-22276860f346']) } } From dee3f65843489a765003160508ba6dcd4be3e3cb Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Mon, 3 Apr 2023 10:10:38 +0200 Subject: [PATCH 3/6] add the service webhook call --- Jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 8163c3d..3008ba9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,6 +32,12 @@ pipeline { } } } + post { + success { + sh 'echo triggering the portainer service webhook' + sh 'curl https://portainer.d4science.org/api/webhooks/e355d76f-38eb-48a7-adb5-ba960443e2e0' + } + } } stage('Remove Unused docker image') { steps{ From 00954fb2bb86a7c3b93e22fb27d6dbc078f5363a Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Mon, 3 Apr 2023 10:12:20 +0200 Subject: [PATCH 4/6] fix service webhook url --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3008ba9..ffaa2a4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,7 +35,7 @@ pipeline { post { success { sh 'echo triggering the portainer service webhook' - sh 'curl https://portainer.d4science.org/api/webhooks/e355d76f-38eb-48a7-adb5-ba960443e2e0' + sh 'curl https://portainer.d4science.org/api/webhooks/7912a372-ce48-4931-b85e-28694c93b1e8' } } } From 8294bc2a472b138f18e6a7d6d950e1caafae4204 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Mon, 3 Apr 2023 10:31:37 +0200 Subject: [PATCH 5/6] fix webhook call --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ffaa2a4..001a148 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,7 +35,7 @@ pipeline { post { success { sh 'echo triggering the portainer service webhook' - sh 'curl https://portainer.d4science.org/api/webhooks/7912a372-ce48-4931-b85e-28694c93b1e8' + sh 'curl -X POST https://portainer.d4science.org/api/webhooks/7912a372-ce48-4931-b85e-28694c93b1e8' } } } From 26bf36ce8c94003910df113f26ebf4f8d9f1ba18 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Mon, 3 Apr 2023 10:33:17 +0200 Subject: [PATCH 6/6] switch to main branch --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 001a148..e64d481 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,7 +11,7 @@ pipeline { stages { stage('Cloning Git') { steps { - git([url: git_url, branch: 'feature/24899', credentialsId: '88b54962-1c0e-49cb-8155-22276860f346']) + git([url: git_url, branch: 'main', credentialsId: '88b54962-1c0e-49cb-8155-22276860f346']) } }