runzexia
pipeline {
agent {
node {
label ‘maven’
}
}
stages {
stage(‘Checkout SCM’) {
steps {
git(url: ‘http://10.10.8.182/hxpaas/gcweb.git’, credentialsId: ‘gitlab-id’, branch: ‘master’, changelog: true, poll: false)
}
}
stage(‘Unit Test’) {
steps {
container(‘maven’) {
sh ‘mvn clean -o -gs pwd
/configuration/settings.xml test’
}
}
}
stage('Code Analysis') {
steps {
container('maven') {
withCredentials([string(credentialsId : 'sonar-token' ,variable : 'SONAR_TOKEN' ,)]) {
withSonarQubeEnv('sonar') {
sh 'mvn sonar:sonar -o -gs `pwd`/configuration/settings.xml -Dsonar.branch=$BRANCH_NAME -Dsonar.login=$SONAR_TOKEN'
}
}
timeout(unit: 'HOURS', activity: true, time: 1) {
waitForQualityGate 'true'
}
}
}
}
stage('Build and Push') {
steps {
container('maven') {
sh 'mvn -o -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER .'
withCredentials([usernamePassword(credentialsId : 'dockerhub-id' ,passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER'
}
}
}
}
stage('Artifacts') {
steps {
archiveArtifacts 'target/*.war'
}
}
stage('Deploy to DEV') {
steps {
input(message: '@admin ', submitter: 'admin')
kubernetesDeploy(enableConfigSubstitution: true, deleteResource: false, kubeconfigId: 'demo-kubeconfig', configs: 'deploy/dev/**')
mail(to: '15556695962@163.com', subject: '流水线完成', body: '应用部署完成')
}
}
}
}