Skip to content

Commit

Permalink
Adicionando try catch no Jenkinsfile
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoallmeida committed Jan 19, 2024
1 parent d9b0760 commit 79c100b
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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()
}

}

0 comments on commit 79c100b

Please # to comment.