-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
117dfe8
commit ea3f84a
Showing
1 changed file
with
6 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,7 @@ | ||
def containerName="springbootdocker" | ||
def tag="latest" | ||
def dockerHubUser="anujsharma1990" | ||
def gitURL="https://github.com/anujdevopslearn/SpringBootDocker.git" | ||
@Library(["JenkinsSharedLibrary@main"]) _ | ||
|
||
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' | ||
} | ||
} | ||
mavenBuild( | ||
gitURL = "https://github.com/anujdevopslearn/SpringBootDocker", | ||
productType = "docker" | ||
pomfileName = "pom.xml" | ||
) |