代码拉取完成,页面将自动刷新
podTemplate(label: 'glsc-zb-jdk8-sonar', containers: [
containerTemplate(name: 'jnlp', image: '10.197.49.110:9080/glk8s/jenkins/inbound-agent:4.13.3-1-jdk11',runAsUser: '0'),
containerTemplate(name: 'git', image: 'alpine/git', ttyEnabled: true, command: 'cat',runAsUser: '0'),
containerTemplate(name: 'maven', image: 'maven:3.8.6-openjdk-8', command: 'cat', ttyEnabled: true,runAsUser: '0'),
containerTemplate(name: 'maven17', image: '10.197.49.110:9080/glk8s/maven:3.9.6-eclipse-temurin-17-alpine', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'docker', image: 'docker:19.03.8', command: 'cat', ttyEnabled: true,runAsUser: '0')
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
persistentVolumeClaim(mountPath: '/root/.m2/', claimName: 'maven-m2', readOnly: false)
],
) {
node('glsc-zb-jdk8-sonar') {
// 组件名 -> 文件名 镜像名 deployment名
def component="zb-dp"
// maven 版本 -> 文件名
def version="1.0"
// springprofile -> Dockerfile deployment
def springProfile = env.giteeSourceBranch
// jenkins 中 git 的用户名密码
def gitCredentialsID="zhangsx-gitee"
// git 库地址
def gitURL = "http://10.197.49.32:88/apptuandui/zb-dp.git"
// git 拉取的分支
def branch = env.giteeSourceBranch
// jenkins 中的 dockerregistry 用户名密码
def dockerRegistrySecret = "fb2dd289-3054-4d98-9b94-2b5450e1a4ef"
def harborURL="10.197.49.110:9080"
def harborProject = "glzb"
def dockerprefix = "${harborURL}/${harborProject}/${component}"
def kubernetesNameSpace="glzb"
def file="${component}-${version}.jar"
def owncloudFolderMaster="glzb"
def owncloudFolderPre="glzb-pre"
def owncloudFolder=""
//运行时获取
def gitCommit = ""
def buildtime =""
stage('prepare env') {
container('git') {
if(env.giteeSourceBranch==null){
sh "echo \"trigger not by Gitee branch will be test\""
branch="test"
springProfile="test"
}else{
branch=env.giteeSourceBranch
springProfile=env.giteeSourceBranch
}
sh "echo \"current branch is ${branch}\""
if(branch == 'pre' ){
owncloudFolder=owncloudFolderPre
sh "echo \"owncloud folder will be ${owncloudFolder}\""
}
if(branch == 'master' ){
owncloudFolder=owncloudFolderMaster
sh "echo \"owncloud folder will be ${owncloudFolder}\""
}
}
}
stage('Clone Repository') {
container('git') {
git(
url: "${gitURL}",
credentialsId: "${gitCredentialsID}",
branch: "${branch}"
)
sh 'ls -la'
gitCommit = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
buildtime = sh(returnStdout: true, script: 'date +%Y%m%d%H%M%S').trim()
}
}
stage('Maven Build') {
container('maven') {
sh "java -version"
sh "mvn clean compile"
}
}
stage('Maven11 sonar'){
container('maven17') {
withSonarQubeEnv('sonar-in-k8s') {
// 执行SonarQube扫描
sh "mvn sonar:sonar"
}
}
}
stage('Maven Build') {
container('maven') {
sh "java -version"
sh "mvn package"
}
}
stage('Docker Build and Push'){
container('docker'){
if(branch == 'test' ){
sh "sed \"s#<FILE>#${file}#\" devops/Dockerfile | sed \"s#<SPRINGPROFILE>#${springProfile}#\" > Dockerfile"
sh "cat Dockerfile"
sh "docker build -t ${dockerprefix}:${gitCommit} ."
sh "docker tag ${dockerprefix}:${gitCommit} ${dockerprefix}:latest "
docker.withRegistry("http://${harborURL}", dockerRegistrySecret) {
image = docker.image("${dockerprefix}:${gitCommit}")
image.push()
image = docker.image("${dockerprefix}:latest")
image.push()
}
sh "docker rmi ${dockerprefix}:latest"
sh "docker rmi ${dockerprefix}:${gitCommit}"
}
else{
sh "echo \"not test branch\""
}
}
}
stage('Kubernetes Deploy'){
container('docker'){
if(branch == 'test' ){
sh "sed \"s#<COMPONENT>#${component}#\" devops/deployment.yaml | sed \"s#<SPRINGPROFILE>#${springProfile}#\" | sed \"s#<BUILDTIME>#${buildtime}#\" | sed \"s#<TAG>#${gitCommit}#\" > k8s-${component}-deployment.yaml"
sh "cat k8s-${component}-deployment.yaml"
sshPublisher(
publishers: [sshPublisherDesc(configName: "webbusi", transfers: [
sshTransfer(cleanRemote: false, excludes: '',
sourceFiles: "k8s-${component}-deployment.yaml",
remoteDirectory: "/", //虽然是 / 但是实际上取的是 jenkins的 全局配置的 远程服务器的 remote directory 和这个值合并后的值 本次对应omk8s1
execCommand: '''
cd /home/zhangsx/
kubectl apply -f '''+"k8s-${component}-deployment.yaml"+'''
rm -f /home/zhangsx/'''+"k8s-${component}-deployment.yaml"+'''
''',
execTimeout: 30000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectorySDF: false,
removePrefix: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
}
else{
sh "echo \"not test branch\""
}
}
}
stage('copy to qudao share owncloud'){
container('docker'){
if(branch == 'test' ){
sh "echo \"not pre or master branch\""
}else{
sshPublisher(
publishers: [sshPublisherDesc(configName: "qudaoshare", transfers: [
sshTransfer(cleanRemote: false, excludes: '',
sourceFiles: "target/${file}",
remoteDirectory: "/", //虽然是 / 但是实际上取的是 jenkins的 全局配置的 远程服务器的 remote directory 和这个值合并后的值 本次对应omk8s1
execCommand: '''
cd /data/groupqudao
rm -rf /data/groupqudao/'''+"${owncloudFolder}/${file}"+'''
mv target/'''+"${file}"+''' /data/groupqudao/'''+"${owncloudFolder}"+'''
rm -rf /data/groupqudao/target
ls -la /data/groupqudao/'''+"${owncloudFolder}"+'''
''',
execTimeout: 30000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectorySDF: false,
removePrefix: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
}
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。