1 Star 1 Fork 0

joneyhsiao/jenkins_cicd_practice

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile_build 4.06 KB
一键复制 编辑 原始数据 按行查看 历史
node {
def nexusServer = '192.168.64.31:8081'
def nexusRepository = 'test'
def mvnHome = tool name: 'maven-3.5.0', type: 'maven'
def buildNumber
def projectName = 'test'
def projectNameConfig = 'test'
def gitBranch = env.BRANCH_NAME
def counterJobName = 'test_BuildCounter'
def autoDeployOn = []
def aemArtifactList = [
[ name: 'all', path: "${projectNameConfig}.all/target", file: "${projectNameConfig}-all-1.0-SNAPSHOT.zip" ]
]
dir(projectName) {
deleteDir()
stage('Build preparation') {
def counterJob = build job: counterJobName , parameters: [string(name: 'PARENT_BRANCH', value: "${projectName}_BuildFlow/${gitBranch}")]
buildNumber = counterJob.getNumber().toString()
}
stage('Git checkout') {
try {
git branch: gitBranch, credentialsId: 'git-credentials', url: 'git@git.com:test/test.git'
} catch (error) {
build job: 'Service_Set_Status' , parameters: [string(name: 'JOB_NAME', value: "${counterJobName}"), string(name: 'JOB_NUMBER', value: "${buildNumber}")]
throw error
}
}
stage('Build AEM artifacts') {
try {
sh "${mvnHome}/bin/mvn clean package"
} catch (error) {
build job: 'Service_Set_Status' , parameters: [string(name: 'JOB_NAME', value: "${counterJobName}"), string(name: 'JOB_NUMBER', value: "${buildNumber}")]
throw error
}
}
stage("SonarQube + JaCoCO analyze") {
try {
step([$class: 'JacocoPublisher', execPattern:'**/**.exec', classPattern: '**/classes', sourcePattern: '**/src/main', exclusionPattern: ''])
withSonarQubeEnv('192.168.64.32') {
sh "${mvnHome}/bin/mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true"
sh "${mvnHome}/bin/mvn sonar:sonar -Dsonar.language=java -Dsonar.branch=JAVACode -Dsonar.projectVersion=${buildNumber}_${gitBranch} -Dsonar.projectName=${projectName}-${gitBranch}-branch"
sh "${mvnHome}/bin/mvn sonar:sonar -Dsonar.language=js -Dsonar.branch=JSCode -Dsonar.projectVersion=${buildNumber}_${gitBranch} -Dsonar.projectName=${projectName}-${gitBranch}-branch"
}
//timeout(time: 20, unit: 'MINUTES') {
// def sonarGateCheck = waitForQualityGate()
// if ( sonarGateCheck.status != 'OK' ) {
// error 'Analyze: SonarQube (Quality Gate check failed)'
// }
//}
} catch (error) {
build job: 'Service_Set_Status' , parameters: [string(name: 'JOB_NAME', value: "${counterJobName}"), string(name: 'JOB_NUMBER', value: "${buildNumber}")]
throw error
}
}
stage("Upload AEM artifacts to Nexus") {
try {
for ( artifact in aemArtifactList ) {
dir(artifact.path) {
def artifactName = "${projectNameConfig}-${artifact.name}"
//nexusArtifactUploader artifacts: [[artifactId: artifactName, classifier: '', file: artifact.file, type: 'zip']], credentialsId: 'jenkins-on-nexus', groupId: gitBranch, nexusUrl: nexusServer, nexusVersion: 'nexus3', protocol: 'http', repository: nexusRepository, version: buildNumber
sh "curl -v -u admin:admin123 --upload-file ${artifact.file} http://${nexusServer}/repository/${nexusRepository}/${gitBranch}/${artifactName}/${buildNumber}/${artifactName}-${buildNumber}.zip"
sleep 1
}
}
} catch (error) {
build job: 'Service_Set_Status' , parameters: [string(name: 'JOB_NAME', value: "${counterJobName}"), string(name: 'JOB_NUMBER', value: "${buildNumber}")]
throw error
}
}
for ( autoDeploy in autoDeployOn ) {
if ( gitBranch == autoDeploy.branch ) {
def envList = autoDeploy.environment.split(',')
for (int i = 0; i < envList.size(); i++) {
def loopItem = envList[i]
stage("Automatic deployment on ${loopItem}") {
try {
build job: 'test_Deploy' , parameters: [string(name: 'test_BuildCounter', value: "nulljob/${counterJobName}/${buildNumber}"), string(name: 'test_environment', value: envList[i])]
} catch (error) {
build job: 'Service_Set_Status' , parameters: [string(name: 'JOB_NAME', value: "${counterJobName}"), string(name: 'JOB_NUMBER', value: "${buildNumber}")]
throw error
}
}
}
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Groovy
1
https://gitee.com/joneyhsiao/jenkins_cicd_practice.git
git@gitee.com:joneyhsiao/jenkins_cicd_practice.git
joneyhsiao
jenkins_cicd_practice
jenkins_cicd_practice
master

搜索帮助