-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
95 lines (68 loc) · 2.69 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
pipeline{
agent any
environment {
AWS_ACCOUNT_ID="982291412478"
AWS_DEFAULT_REGION="ap-southeast-1"
IMAGE_REPO_NAME="jenkins-pipeline"
VERSION = "${env.BUILD_ID}"
REPOSITORY_URI = "982291412478.dkr.ecr.ap-southeast-1.amazonaws.com/jenkins-pipeline"
}
stages {
stage('Git Checkout'){
steps{
script{
git branch: 'main', url: 'https://github.com/saad946/Jenkins-SonarQube-FluxCD-CICD.git'
}
}
}
stage('UNIT testing'){
steps{
script{
sh 'mvn test'
}
}
}
stage('Integration testing'){
steps{
script{
sh 'mvn verify -DskipUnitTests'
}
}
}
stage('Maven build'){
steps{
script{
sh 'mvn clean install'
}
}
}
stage('Static code analysis'){
steps{
script{
withSonarQubeEnv(credentialsId: 'sonars-tokens') {
sh 'mvn clean package sonar:sonar'
}
}
}
}
stage('Quality Gate Status'){
steps{
script{
waitForQualityGate abortPipeline: false, credentialsId: 'sonars-tokens'
}
}
}
// Uploading Docker images into AWS ECR
stage('Pushing to ECR') {
steps{
script {
sh "aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
sh "docker build -t ${IMAGE_REPO_NAME}:${VERSION} ."
sh "docker tag ${IMAGE_REPO_NAME}:$VERSION ${REPOSITORY_URI}:${VERSION}"
sh "docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}:${VERSION}"
sh "docker rmi ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}:${VERSION}"
}
}
}
}
}