-
Notifications
You must be signed in to change notification settings - Fork 150
/
Jenkinsfile
79 lines (77 loc) · 2.84 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
pipeline{
environment {
account = "${environment}"
eks_cluster_name = "eks-${account}"
artifacts_dir = "${env.WORKSPACE}/artifacts"
aws_region = "${params.aws_region}"
job_root_dir="${env.WORKSPACE}"
}
tools {
maven 'maven-3.8.1'
}
agent {
label 'master'
}
stages{
stage('Initialize workspace') {
steps {
// Make sure the directory is clean
dir("${artifacts_dir}") {
deleteDir()
}
sh(script: "mkdir -p ${artifacts_dir}", label: 'Create artifacts directory')
}
}
stage('git stage'){
steps{
git branch: 'main', url: 'https://github.com/cloudtechmasters/springboot-maven-course-micro-svc.git'
}
}
stage('build maven project '){
steps{
sh 'mvn clean package'
}
}
stage('Generate kubeconfig for the cluster') {
steps {
script {
env.KUBECONFIG = "${artifacts_dir}/${eks_cluster_name}-kubeconfig"
sh 'chmod +x ${WORKSPACE}/generate_kubeconfig_eks.sh'
}
sh(script: '${WORKSPACE}/generate_kubeconfig_eks.sh', label: 'Generate kubeconfig file')
}
}
stage('Get the cluster details') {
steps {
script {
sh '''kubectl apply -f deployment.yml
kubectl apply -f service.yml
kubectl get all
'''
}
}
}
}
post {
cleanup {
cleanWs(cleanWhenFailure: false)
}
always {
echo 'This will always run'
}
success {
echo 'This will run only if successful'
mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '[email protected]', mimeType: 'text/html', replyTo: '[email protected]', subject: "SUCCESS CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
failure {
mail bcc: '', body: "<b>Example</b><br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '[email protected]', mimeType: 'text/html', replyTo: '[email protected]', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "[email protected]";
}
unstable {
echo 'This will run only if the run was marked as unstable'
}
changed {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
}
}