devops基于jenkins和k8s的cicd相关基于Library完成持续集成(三 )
cicd自动化相关
·
实现目标
简化上一个django项目的cicd流程,直接调用方法使用相关流程
jenkinsfile修改成声明试
声明式和脚本式的主要区别可以参考下面文章:
https://blog.csdn.net/qq_23483671/article/details/124081218
新建一个Library
1 把相关的方法都提交单独建一个groovy项目,提交到gitlab中
2.把Global Pipeline Libraries再jenkins上面添加
然后我们修改项目的jenkinsfile
@Library('test-devops') _
pipeline {
agent {
kubernetes {
cloud 'k8s115'
label 'slave'
inheritFrom 'jenkins-slave'
// defaultContainer 'node'
yaml libraryResource('base/base.yaml')
}
}
options {
timeout(time: 20, unit: 'MINUTES')
//gitLabConnection('gitlab')
}
environment {
IMAGE_REPO = "192.168.200.118/library/qfcsspiders"
IMAGE_CREDENTIAL = "dockerhub"
}
stages {
stage('checkout') {
steps {
checkout scm
}
}
stage('CI'){
failFast true
parallel {
stage('Unit Test') {
steps {
echo "Unit Test Stage Skip..."
}
}
stage('Code Scan') {
steps {
container('tools') {
script {
devops.scan().start()
}
}
}
}
}
}
stage('docker-image') {
steps {
container('docker') {
script{
devops.docker(
"${IMAGE_REPO}",
"${GIT_COMMIT}",
IMAGE_CREDENTIAL
).build().push()
}
}
}
}
stage('deploy') {
steps {
container('kubectl') {
script{
devops.deploy("manifests", "manifests/k8s.yaml").start()
}
}
}
}
stage('integration test') {
steps {
container('tools') {
script{
devops.robotTest("qfcsspiders")
}
}
}
}
}
post {
success {
script{
devops.notificationSuccess("qfcsspiders","wechat")
}
}
failure {
script{
devops.notificationFailed("qfcsspiders","wechat")
}
}
}
}
其中我们把测试用力定义另一个jenkins项目,这样两个就相互独立,测试人员单独去维护
This project is parameterized用于从主项目传入项目名称给这个测试项目,相关逻辑可以看代码
代码地址
1 jenkins-shared-library:
https://github.com/chenzhenhua86/jenkins-shared-library
2.
robot-cases
https://github.com/chenzhenhua86/robot-cases
更多推荐
已为社区贡献2条内容
所有评论(0)