-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
106 lines (94 loc) · 3.13 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
96
97
98
99
100
101
102
103
104
105
106
pipeline {
agent any
tools {
go 'go1.21.6'
}
environment {
SONAR_TOKEN = credentials('SONAR_TOKEN') // Reference Jenkins credential ID
}
stages {
stage('Unit Test') {
steps {
script {
sh 'go test -v ./tests/benchMarking/benchMarking_test.go'
}
}
}
stage('Coverage Report') {
steps {
script {
sh 'go test -coverprofile=coverage.out'
sh 'go tool cover -html=coverage.out -o coverage.html'
}
archiveArtifacts 'coverage.html'
}
}
stage('Run SonarQube Analysis') {
steps {
script {
sh '/usr/local/sonar/bin/sonar-scanner -X -Dsonar.organization=wm-demo -Dsonar.projectKey=wm-demo_hello-webapp-golang -Dsonar.sources=. -Dsonar.host.url=https://sonarcloud.io'
}
}
}
stage('Build') {
steps {
script {
// Adjust these commands based on how you build and upload your Go application to Nexus
sh 'go build -o main .'
// sh 'curl -u username:password -X PUT --upload-file your-app https://nexus.example.com/repository/your-repo/your-app/1.0.0/your-app-1.0.0'
}
archiveArtifacts 'main'
}
}
stage('Build Docker Image') {
steps {
script {
sh 'docker build -t dab8106/hellogo .'
}
}
}
stage('Push Docker Image') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'DOCKER_CREDENTIALS', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh """
echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin
docker push dab8106/hellogo
"""
}
}
}
}
// stage('Terraform Apply') {
// environment {
// AWS_ACCESS_KEY_ID = credentials('AWS_ACCESS_KEY_ID')
// AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
// }
// steps {
// script {
// sh '''
// export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
// export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
// cd ./terraform
// terraform init
// terraform apply -auto-approve
// '''
// }
// }
// }
stage('Run Ansible Playbook') {
steps {
script {
sh '''
ansible-playbook ansible/deploy-container.yaml
'''
}
}
}
}
post {
always {
cleanWs()
}
}
}