重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
pipeline {//指定任务在哪个集群节点上执行
agent any
//声明环境变量,方便后面使用
environment {key='value'
}
parameters {choice(name: 'BRANCH', choices: ['dev', 'test', 'master'], description: '代码分支')
}
stages {stage('检查版本号') { when { equals expected: 'master', actual: params.BRANCH
equals expected: '', actual: params.VERSION
}
steps { echo 'Aborting the build because conditions are not met'
error("Aborting the build because conditions are not met")
}
}
stage('拉取git仓库代码') {steps {checkout scmGit(branches: [[name: '*/${BRANCH}']], extensions: [], userRemoteConfigs: [[credentialsId: 'da081bcb-677d-4e23-b864-f1741cd9835c', url: 'http://192.168.0.101:9992/xxx/xxx.git']])
echo '拉取git仓库代码-SUCCESS'
}
}
stage('通过maven构建项目') {steps {sh 'mvn clean package -DskipTests'
echo '通过maven构建项目-SUCCESS'
}
}
// stage('代码检查 ') {// steps {// withSonarQubeEnv('SonarQube') {// sh '''mvn sonar:sonar -DskipTests \\
// -Dsonar.projectKey=beef-service \\
// -Dsonar.host.url=http://192.168.0.102:9000/sonarqube \\
// -Dsonar.login=squ_17b9345e946d3f55ed4dfbb531a6b237180d27b2'''
// }
// echo '通过maven构建项目-SUCCESS'
// }
// }
// stage("Quality gate") {// steps {// waitForQualityGate abortPipeline: true
// }
// }
stage('通过docker制作自定义镜像') {steps {script {if ( branch == 'master' ) {sh '/usr/bin/docker build -t 192.168.0.103:18082/docker/beef-service-${BRANCH}:${VERSION} .'
}else{sh '/usr/bin/docker build -t 192.168.0.103:18082/docker/beef-service-${BRANCH} .'
}
}
echo 'docker制作自定义镜像-SUCCESS'
}
}
stage('将自定义镜像推送到仓库中') {steps {script {if ( branch == 'master' ) {sh 'docker push 192.168.0.103:18082/docker/xxx-service-${BRANCH}:${VERSION}'
}else{sh 'docker push 192.168.0.103:18082/docker/xxx-service-${BRANCH}'
}
}
echo '推送到harbor仓库-SUCCESS'
}
}
stage('部署'){steps{ script{switch(BRANCH)
{case 'dev':
sh '''curl -X PUT \\
-H "Content-Type: application/yaml" \\
-H "Cookie: KuboardUsername=admin; KuboardAccessKey=3amr52y36jsw.apw7jitm62pakb2463znfdptfm7hbx4k" \\
-d \'{"kind":"deployments","namespace":"default","name":"xxx-service"}\' \\
"http://192.168.0.132/kuboard-api/cluster/k8s-dev/kind/CICDApi/admin/resource/restartWorkload"'''
echo 'deploy dev SUCCESS'
break
case 'test':
sh '''curl -X PUT \\
-H "Content-Type: application/yaml" \\
-H "Cookie: KuboardUsername=admin; KuboardAccessKey=3amr52y36jsw.apw7jitm62pakb2463znfdptfm7hbx4k" \\
-d \'{"kind":"deployments","namespace":"default","name":"xxx-service"}\' \\
"http://192.168.0.132/kuboard-api/cluster/k8s-test/kind/CICDApi/admin/resource/restartWorkload"'''
echo 'deploy test SUCCESS'
break
}
}
}
}
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
创新互联公司-专业网站定制、快速模板网站建设、高性价比兖州网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式兖州网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖兖州地区。费用合理售后完善,十多年实体公司更值得信赖。