//Sonarqube项目的唯一标识
def sonar_projectKey = "xxxx-pro"
//Sonarqube项目的名称,用于显示在 sonarqube web 界面
def sonar_projectName = "xxxx-pro"
//git凭证ID
def git_auth = ""
//git的url地址
def git_url = "xxxx.git"
//镜像私有仓库的url地址
def image_url = "xxxx.aliyuncs.com"
//镜像仓库命名空间
def repositories_namespace = "hka-img"
//镜像仓库中项目的名字
def repositories_projectName = "xxxxxx"
//阿里云账号
def aliCloud_account = "account"
//阿里云密码
def aliCloud_password = "pwd"
pipeline {
agent any //任意可用的agent都可以执行
stages {
stage('拉取代码') {
steps {
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: "${git_branche}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]]
echo 'pull code'
}
}
// stage('Sonarqube analysis'){
// steps {
// //注意:下面的SonarQube-Server和系统配置SonarQube installations的Name必须一致, 大小写敏感
// withSonarQubeEnv("sonarqube"){
// sh "mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar -Dsonar.java.binaries=${WORKSPACE} -Dsonar.projectKey=${sonar_projectKey} -Dsonar.projectName=${sonar_projectName} "
// }
// }
// }
// 检测失败时,不进行后续镜像构建,按需添加
// stage('Quality Gate'){
// steps {
// //代码检测失败,将不再继续执行后面的任务,直接退出,报告返回的超时时长设为5分钟
// timeout(time:5, unit:'MINUTES'){
// waitForQualityGate abortPipeline: true
// }
// }
// }
stage('构建项目') {
steps {
sh 'mvn package -Dmaven.test.skip=true'
echo 'build project'
}
}
stage('将镜像推送到阿里云仓库') {
steps {
sh 'cp businesstrip-service/dockerfile businesstrip-service/target/'
dir('businesstrip-service/target') {
sh 'rm -rf forDocker'
sh 'mkdir forDocker'
sh 'cp *.jar forDocker/'
sh 'cp dockerfile forDocker/'
dir('forDocker') {
//使用凭证的方式登入,避免直接写aliyun的用户和密码
sh "docker login -u ${aliCloud_account} -p ${aliCloud_password} ${image_url}"
//构建镜像
sh "docker build -t ${image_url}/${repositories_namespace}/${repositories_projectName}:${tag} ."
//镜像上传
sh "docker push ${image_url}/${repositories_namespace}/${repositories_projectName}:${tag}"
echo '镜像上传成功'
}
}
}
}
}
}