Skip to content

Commit ea3f84a

Browse files
Update Jenkinsfile
1 parent 117dfe8 commit ea3f84a

1 file changed

Lines changed: 6 additions & 42 deletions

File tree

Jenkinsfile

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
1-
def containerName="springbootdocker"
2-
def tag="latest"
3-
def dockerHubUser="anujsharma1990"
4-
def gitURL="https://github.com/anujdevopslearn/SpringBootDocker.git"
1+
@Library(["JenkinsSharedLibrary@main"]) _
52

6-
node {
7-
def sonarscanner = tool name: 'SonarQubeScanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
8-
stage('Checkout') {
9-
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: gitURL]]]
10-
}
11-
12-
stage('Build'){
13-
sh "mvn clean install"
14-
}
15-
16-
stage("Image Prune"){
17-
sh "docker image prune -f"
18-
}
19-
20-
stage('Image Build'){
21-
sh "docker build -t $containerName:$tag --pull --no-cache ."
22-
echo "Image build complete"
23-
}
24-
25-
stage('Push to Docker Registry'){
26-
withCredentials([usernamePassword(credentialsId: 'dockerHubAccount', usernameVariable: 'dockerUser', passwordVariable: 'dockerPassword')]) {
27-
sh "docker login -u $dockerUser -p $dockerPassword"
28-
sh "docker tag $containerName:$tag $dockerUser/$containerName:$tag"
29-
sh "docker push $dockerUser/$containerName:$tag"
30-
echo "Image push complete"
31-
}
32-
}
33-
34-
stage("SonarQube Scan"){
35-
withSonarQubeEnv(credentialsId: 'SonarQubeToken') {
36-
sh "${sonarscanner}/bin/sonar-scanner"
37-
}
38-
}
39-
40-
stage("Ansible Deploy"){
41-
ansiblePlaybook inventory: 'hosts', playbook: 'deploy.yaml'
42-
}
43-
}
3+
mavenBuild(
4+
gitURL = "https://github.com/anujdevopslearn/SpringBootDocker",
5+
productType = "docker"
6+
pomfileName = "pom.xml"
7+
)

0 commit comments

Comments
 (0)