From a4f64f4e8d175b8407470ef7365e0b9dc2769108 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Francisco-Javier=20Ram=C3=B3n=20Salguero?= Date: Mon, 14 Sep 2020 16:39:02 +0200 Subject: [PATCH] Improvements to Jenkinsfile structure to publish image --- Jenkinsfile | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 049f6e9..29a4109 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,19 +1,37 @@ +def dockerImage + pipeline { - agent none - stages { -/* stage('Test') { - agent { dockerfile true } - steps { - sh 'echo HOLA' - } - } -*/ - stage('Build') { - agent any - steps { - sh 'docker build .' - sh 'echo PUBLISH' - } + environment { + imagename = "opensourcemano/api-fe" + registryCredential = '' // To be updated with actual ID in the future + } + agent any + stages { + stage('Build API-FE image') { + steps{ + sh "echo Building API-FE image" + script { + dockerImage = docker.build "${env.imagename}:${env.BUILD_NUMBER}" } + } + } + stage('Upload to Docker registry') { + steps{ + sh "echo Here it would upload the image with appropriate tags: build number, latest" + /*script { + docker.withRegistry( '', registryCredential ) { + dockerImage.push("${env.BUILD_NUMBER}") + dockerImage.push('latest') + } + }*/ + } + } + stage('Remove unused Docker image') { + steps{ + sh "docker rmi ${imagename}:${BUILD_NUMBER}" + // Commented until "upload" stage can be uncommented as well + //sh "docker rmi ${imagename}:latest" + } } + } } -- 2.25.1