中国经济观察网 | 手机客户端 |
当前位置: 首页 > 行业

templates目录用于存放流水线模板

作者:杜玉梅    栏目:行业    来源:TechWeb   发布时间:2021-12-26 18:33   阅读量:14748   

内容摘要:还是按照之前的目录结构完成的,jobs目录用于存放作业模板templates目录用于存放流水线模板这次使用default—pipeline.yml作为所有作业的基础模板 作业模板 作业分为Build,test,codeanalysi...

还是按照之前的目录结构完成的,jobs目录用于存放作业模板templates目录用于存放流水线模板这次使用default—pipeline.yml作为所有作业的基础模板

templates目录用于存放流水线模板

作业模板

作业分为Build,test,codeanalysis,artifactory,deploy部分,在每个作业中配置了rules功能开关,由变量控制最终作业的运行。

jobs/build.yml 构建作业模板

包含两个作业模板,分别是普通的构建模板和docker 镜像构建模板。

$BUILD_SHELLvariables:GIT_CHECKOUT:"true"rules:—if:"$RUN_PIPELINE_BUILD'no'"when:never—when:always##构建镜像.build—docker:stage:buildimagescript:—dockerlogin—u$CI_REGISTRY_USER—p$CI_REGISTRY_PASSWD$CI_REGISTRY—dockerbuild—t$IMAGE_NAME—f$DOCKER_FILE_PATH.—dockerpush$IMAGE_NAME—dockerrmi$IMAGE_NAMErules:—if:"$RUN_BUILD_IMAGE'no'"when:never—when:always

jobs/test.yml 测试作业模板

主要用于运行项目单元测试,例如maven,gradle,npm单元测试。。

#单元测试.test:stage:testscript:—$TEST_SHELLartifacts:reports:junit:$JUNIT_REPORT_PATHrules:—if:"$RUN_PIPELINE_TEST'no'"when:never—when:always

jobs/codeanalysis.yml 代码扫描模板

包含两个作业模板,分别为扫描作业和获取扫描结果这里面将扫描参数进行了分类,通用的项目参数,特殊的合并请求参数,自定义的项目参数

jobs/artifactory.yml 制品管理作业

包含两个作业,制品上传与下载使用artifactory制品库接口

##制品库相关##.deploy—artifact:stage:deploy—artifactscript:—echo"curl—u$ARTIFACT_USER:$ARTIFACT_PASSWD—T$ARTIFACT_PATH$ARTIFACTORY_URL/$ARTIFACTORY_NAME/$TARGET_FILE_PATH/$TARGET_ARTIFACT_NAME"—curl—u$ARTIFACT_USER:$ARTIFACT_PASSWD—T$ARTIFACT_PATH"$ARTIFACTORY_URL/$ARTIFACTORY_NAME/$TARGET_FILE_PATH/$TARGET_ARTIFACT_NAME"rules:—if:"$RUN_DEPLOY_ARTIFACTS'no'"when:never—when:always.down—artifact:stage:down—artifactscript:—curl—u$ARTIFACT_USER:$ARTIFACT_PASSWD—O"$ARTIFACTORY_URL/$ARTIFACTORY_NAME/$TARGET_FILE_PATH/$TARGET_ARTIFACT_NAME"—ls

jobs/deploy.yml 发布作业模板

发布基于k8s的发布和回滚配置。然而,探索混合所有制的职业院校办学模式一直是职业教育行业的痛点。学校和企业犹豫观望,社会力量参与和举办职业教育的动力仍然不足。我们期待更详细和明确的政策和措施。

templates/default—pipeline.yml 模板分成个部分

include导入作业模板 variables 定义全局变量 workflow 定义流水线控制 jobs 构建与发布作业

include导入作业模板

include:—project:'cidevops/cidevops—newci—service'ref:masterfile:'jobs/build.yml'—project:'cidevops/cidevops—newci—service'ref:masterfile:'jobs/test.yml'—project:'cidevops/cidevops—newci—service'ref:masterfile:'jobs/codeanalysis.yml'—project:'cidevops/cidevops—newci—service'ref:masterfile:'jobs/deploy.yml'—project:'cidevops/cidevops—newci—service'ref:masterfile:'jobs/artifactory.yml'

variables 定义全局变量

流水线设置

$CI_COMMIT_REF_NAME=~/master/"#过滤版本分支和主干分支提交代码触发when:never—if:"$CI_COMMIT_BEFORE_SHA'0000000000000000000000000000000000000000'"#过滤分支创建请求when:never###默认策略—when:always##运行阶段stages:—build—test—parallel01—get_analysis_result—deploy—artifact—deploy—feature—rollout—feature—deploy—uat—rollout—uat—deploy—stag—rollout—stag—deploy—prod—rollout—prodcache:paths:—$CACHE_DIRbefore_script:—export

构建作业配置

#################JobsConfigure#######################构建作业build:image:$BUILD_IMAGEextends:.build##测试作业test:image:$BUILD_IMAGEextends:.testbefore_script:—ls—ls$CACHE_DIR##代码扫描code_analysis:stage:parallel01image:$SONAR_IMAGEextends:.code_analysis##获取构建结果get_analysis_result:image:$CURL_IMAGEextends:.get_analysis_resultneeds:—code_analysis##构建镜像build_image:image:docker:latestservices:—name:docker:dindstage:parallel01extends:.build—docker##上传制品deploy_artifact:image:$CURL_IMAGEstage:deploy—artifactextends:.deploy—artifact##下载制品#down_artifact:#image:$CURL_IMAGE#stage:down_artifact#extends:.down—artifact

发布部署作业配置

$CI_COMMIT_REF_NAME=~/master/||$CI_COMMIT_TAGwhen:never—when:manual##应用回滚rollout_feature:variables:DEPLOY_FILE:'deployment.yaml'ENV_NAME:'feature'stage:rollout—featureimage:$KUBECTL_IMAGEextends:.rollout_k8sneeds:—deploy_featurerules:—if:$RUN_DEPLOY_K8S'no'when:never—if:$CI_COMMIT_REF_NAME=~/^RELEASE—*/||$CI_COMMIT_REF_NAME=~/master/||$CI_COMMIT_TAGwhen:never—when:on_failure#################DeployUATJobsConfigure#######################UATdeploy_uat:variables:DEPLOY_FILE:'config/deployment—uat.yaml'ENV_NAME:'uat'stage:deploy—uatimage:$KUBECTL_IMAGEextends:.deploy_k8senvironment:on_stop:"rollout_uat"rules:—if:$RUN_DEPLOY_K8S'no'when:never—if:$CI_COMMIT_REF_NAME=~/^RELEASE—*/||$CI_COMMIT_REF_NAME=~/master/||$CI_COMMIT_TAGwhen:manual—when:never##UAT应用回滚rollout_uat:variables:DEPLOY_FILE:'config/deployment—uat.yaml'ENV_NAME:'uat'stage:rollout—uatimage:$KUBECTL_IMAGEextends:.rollout_k8sneeds:—deploy_uatrules:—if:$RUN_DEPLOY_K8S'no'when:never—if:$CI_COMMIT_REF_NAME=~/^RELEASE—*/||$CI_COMMIT_REF_NAME=~/master/||$CI_COMMIT_TAGwhen:on_failure—when:never#################DeploySTAGJobsConfigure#######################STAGdeploy_stag:variables:DEPLOY_FILE:'config/deployment—stag.yaml'ENV_NAME:'stag'stage:deploy—stagimage:$KUBECTL_IMAGEextends:.deploy_k8senvironment:on_stop:"rollout_stag"needs:—deploy_uatrules:—if:$RUN_DEPLOY_K8S'no'when:never—if:$CI_COMMIT_REF_NAME=~/^RELEASE—*/||$CI_COMMIT_REF_NAME=~/master/||$CI_COMMIT_TAGwhen:manual—when:never##STAG应用回滚rollout_stag:variables:DEPLOY_FILE:'config/deployment—stag.yaml'ENV_NAME:'stag'stage:rollout—stagimage:$KUBECTL_IMAGEextends:.rollout_k8sneeds:—deploy_stagrules:—if:$RUN_DEPLOY_K8S'no'when:never—if:$CI_COMMIT_REF_NAME=~/^RELEASE—*/||$CI_COMMIT_REF_NAME=~/master/||$CI_COMMIT_TAGwhen:on_failure—when:never#################DeployPRODJobsConfigure#######################PRODdeploy_prod:variables:DEPLOY_FILE:'config/deployment—prod.yaml'ENV_NAME:'prod'stage:deploy—prodimage:$KUBECTL_IMAGEextends:.deploy_k8senvironment:on_stop:"rollout_prod"needs:—deploy_stagrules:—if:$RUN_DEPLOY_K8S'no'when:never—if:$CI_COMMIT_REF_NAME=~/^RELEASE—*/||$CI_COMMIT_REF_NAME=~/master/||$CI_COMMIT_TAGwhen:manual—when:never##PROD应用回滚rollout_prod:variables:DEPLOY_FILE:'config/deployment—prod.yaml'ENV_NAME:'prod'stage:rollout—prodimage:$KUBECTL_IMAGEextends:.rollout_k8sneeds:—deploy_prodrules:—if:$RUN_DEPLOY_K8S'no'when:never—if:$CI_COMMIT_REF_NAME=~/^RELEASE—*/||$CI_COMMIT_REF_NAME=~/master/||$CI_COMMIT_TAGwhen:on_failure—when:never JAVA项目交付流水线

导入作业模板

include:—project:'cidevops/cidevops—newci—service'ref:masterfile:'templates/default—pipeline.yml'

配置项目参数

指定CI文件

运行流水线测试

docker镜像仓库

部署环境演示

Kubernetes集群中应用状态

郑重声明:此文内容为本网站转载企业宣传资讯,目的在于传播更多信息,与本站立场无关。仅供读者参考,并请自行核实相关内容。

相关阅读