You are on page 1of 2

node{

environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "http://10.131.31.204:30000"
NEXUS_REPOSITORY = "maven-snapshots"
NEXUS_CREDENTIAL_ID = "nexus-credentials"
}

stage('SCM Checkout'){
git credentialsId: 'github', url:
'git@gitserver.cboitistcs.com:TCS/jenkins_cicd.git'
}

stage(" Maven Clean Package"){


def mavenHome = tool name: "Maven", type: "maven"
def mavenCMD = "${mavenHome}/bin/mvn"
sh "${mavenCMD} clean package"

stage('Upload Artifacts'){
script{
def mavenPom = readMavenPom file: 'pom.xml'
def nexusRepoName = mavenPom.version.endsWith("SNAPSHOT") ? "maven-
snapshots" :"maven-releases"

nexusArtifactUploader artifacts: [
[artifactId: 'pom.artifactId',
classifier: '',
file: "target/spring-boot-mongo-${mavenPom.version}.jar",
type: 'jar'
]
],
credentialsId: 'nexus-credentials',
groupId: 'pom.groupId',
nexusUrl: '10.131.31.204:30000',
nexusVersion: 'nexus3',
protocol: 'http',
repository: "${nexusRepoName}",
version: "${mavenPom.version}"

}
}

stage('Build Docker Image'){


sh 'docker build -t 10.131.31.204:32000/jenkins_cicd:latest .'
}

stage('Push Docker Image'){


withCredentials([string(credentialsId: 'DOCKER_INTERNAL_REPO', variable:
'DOCKER_INTERNAL_REPO')]) {
sh "docker login -u admin -p ${DOCKER_INTERNAL_REPO} 10.131.31.204:32000"
}
sh 'docker push 10.131.31.204:32000/jenkins_cicd:latest'
sh 'docker logout 10.131.31.204:32000'
}
stage("Deploy To Kubernetes Cluster"){
sh 'kubectl apply -f springBootMongo.yml'
}
}

/**
stage("Deploy To Kubernetes Cluster"){
kubernetesDeploy(
configs: 'springBootMongo.yml',
kubeConfig: [path:'/var/lib/jenkins/.kube/config'],
kubeconfigId: 'KUBECONFIG',
enableConfigSubstitution: true
)
}
**/

You might also like