-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
70 lines (64 loc) · 2.26 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
pipeline {
agent any
environment {
imageName = 'myphpapp'
registryCredentials = 'nexus'
registry = 'localhost:8085/'
dockerImage = ''
}
stages {
stage('checkout') {
steps {
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/assafseif/hello-world']])
}
}
stage('SonarQube Analysis') {
steps {
// Use the SonarQube scanner step with the defined tool
withSonarQubeEnv('SonarQube') {
bat 'C:/Users/assafseif/.jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/SonarQube/bin/sonar-scanner -D"sonar.projectKey=demo-appproject" -D"sonar.sources=." -D"sonar.host.url=http://localhost:9000" -D"sonar.login=sqp_4e9ddf7b33da859f6872b7f3120177a3e6e9fd56"'
}
}
}
stage('build Image') {
steps {
script {
dockerImage = docker.build imageName
}
}
}
// Uploading Docker images into Nexus Registry
stage('Uploading to Nexus') {
steps {
script {
docker.withRegistry('http://' + registry, registryCredentials) {
dockerImage.push('latest')
}
}
}
}
stage('stop previous containers') {
steps {
bat 'docker rm -f myphpcontainer'
}
}
stage('Deploy Application') {
steps {
sh './scripts/deploy.sh' + ' ' + registry + imageName
}
}
}
/*POST BUILD ACTIONS*/
// post {
// success {
// emailext body: "Build succeeded. Check the console output at ${env.BUILD_URL} for details.",
// subject: "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - Success",
// to: '[email protected]'
// }
// failure {
// emailext body: "Build failed. Check the console output at ${env.BUILD_URL} for details.",
// subject: "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - Failure",
// to: '[email protected]'
// }
// }
}