diff --git a/Jenkinsfile b/Jenkinsfile index 80dc594..137aade 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,31 +1,37 @@ node { + try{ - deleteDir() + stage('Clone Repo') { + checkout scm + } - stage('Clone Repo') { - checkout scm + stage('Build Docker Image') { + app = docker.build('joaoallmeida/calculadora-fiis') + } - } - stage('Build Docker Image') { - app = docker.build('joaoallmeida/calculadora-fiis') + stage('Push Docker Image') { + docker.withRegistry('https://registry.hub.docker.com','dockerHubCredentials') { + app.push("${env.BUILD_NUMBER}") + } + } + + stage('Set Environment Variables') { + sh "sed -i 's|latest|${env.BUILD_NUMBER}|' kubernetes/deploy.yaml" + sh "sed -i 's|buildNumber|${env.BUILD_NUMBER}|' kubernetes/deploy.yaml" + } - } - stage('Push Docker Image') { - docker.withRegistry('https://registry.hub.docker.com','dockerHubCredentials') { - app.push("${env.BUILD_NUMBER}") + stage('Deploy to K8s') { + withKubeConfig([credentialsId: 'mykubeconfig']) { + sh 'kubectl apply -f kubernetes/deploy.yaml' + } } - } - - stage('Set Environment Variables') { - sh "sed -i 's|latest|${env.BUILD_NUMBER}|' kubernetes/deploy.yaml" - sh "sed -i 's|buildNumber|${env.BUILD_NUMBER}|' kubernetes/deploy.yaml" - } + } catch (Exception e) { + error "Failed: ${e}" + throw - stage('Deploy to K8s') { - withKubeConfig([credentialsId: 'mykubeconfig']) { - sh 'kubectl apply -f kubernetes/deploy.yaml' - } + } finally { + deleteDir() } } \ No newline at end of file