pipeline {
agent any
tools {
jdk 'jdk8'
}
environment {
harborUser = "admin"
harborPassword = "Harbor12345"
harborAddress = "harbor地址"
harborRepo = "仓库名"
jobName = "打好的docker镜像名"
}
stages {
stage('check') {
steps {
checkout scmGit(branches: [[name: '*/分支名']], extensions: [], userRemoteConfigs: [[credentialsId: 'gitlab-login-user', url: 'gitlab地址']])
}
}
stage('mvn') {
steps {
sh 'mvn clean package -DskipTests'
}
}
stage("SonarQube analysis") {
steps{
withSonarQubeEnv('SonarQube10.6') {
sh 'sonar-scanner -Dsonar.projectKey=要扫描的工程 -Dsonar.projectName=工程名 -Dsonar.projectVersion=1.0.0 -Dsonar.language=java -Dsonar.modules=模块名 -D模块名.sonar.projectName=模块名 -D模块名.sonar.sources=src -Dhntt-模块名.sonar.projectBaseDir=模块根路径 -Dsonar.java.binaries=target'
}
}
}
stage('docker') {
steps {
sh '''
cd dockerfile文件所在目录
docker build -t ${jobName}:${date} .'''
}
}
stage('harbor') {
steps {
sh '''
docker login -u ${harborUser} -p ${harborPassword} ${harborAddress}
docker push ${jobName}:${date}
'''
}
}
}
}