-
Notifications
You must be signed in to change notification settings - Fork 171
/
Jenkinsfile
43 lines (36 loc) · 1.38 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
def containerName="springbootdocker"
def tag="latest"
def dockerHubUser="anujsharma1990"
def gitURL="https://github.com/anujdevopslearn/SpringBootDocker.git"
node {
def sonarscanner = tool name: 'SonarQubeScanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
stage('Checkout') {
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: gitURL]]]
}
stage('Build'){
sh "mvn clean install"
}
stage("Image Prune"){
sh "docker image prune -f"
}
stage('Image Build'){
sh "docker build -t $containerName:$tag --pull --no-cache ."
echo "Image build complete"
}
stage('Push to Docker Registry'){
withCredentials([usernamePassword(credentialsId: 'dockerHubAccount', usernameVariable: 'dockerUser', passwordVariable: 'dockerPassword')]) {
sh "docker login -u $dockerUser -p $dockerPassword"
sh "docker tag $containerName:$tag $dockerUser/$containerName:$tag"
sh "docker push $dockerUser/$containerName:$tag"
echo "Image push complete"
}
}
stage("SonarQube Scan"){
withSonarQubeEnv(credentialsId: 'SonarQubeToken') {
sh "${sonarscanner}/bin/sonar-scanner"
}
}
stage("Ansible Deploy"){
ansiblePlaybook inventory: 'hosts', playbook: 'deploy.yaml'
}
}