Skip to content

Commit

Permalink
Update Jenkinsfile
Browse files Browse the repository at this point in the history
  • Loading branch information
anujdevopslearn authored Apr 9, 2024
1 parent 117dfe8 commit ea3f84a
Showing 1 changed file with 6 additions and 42 deletions.
48 changes: 6 additions & 42 deletions Jenkinsfile
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"
)

0 comments on commit ea3f84a

Please sign in to comment.