定义
是一组过程、方法与系统统称,用于促进开发(应用程序/软件工程)、技术运营和质量保障(QA)部门之间的沟通写作与整合。
Dev:开发人员;
**Ops:运维人员;
持续集成:将应用程序部署之前需要进行开发、测试、构建的过程成为持续集成
持续部署:在敏捷开发中,短时间内将程序多次部署
**

DevOps主要方式
一、 开源自建(基于jenkins)
- 开发提交代码 -> GitLab
- GitLab 通过 WebHook 触发Jenkins构建
- Jenkins 跑构建流程
- 更新 Harbor 的镜像
- 通知K8s触发更新服务
二 云运营商(阿里云或腾讯云)
阿里云和腾讯云所提供的组件都是基于jenkins
目前使用

pipeline {agent anyenvironment {VERSION = readMavenPom().getVersion()}stages {stage("检出") {steps {checkout([$class: 'GitSCM',branches: [[name: env.GIT_BUILD_REF]],userRemoteConfigs: [[url: env.GIT_REPO_URL,credentialsId: env.CREDENTIALS_ID]]])}}stage("构建") {steps {echo "构建中..."sh 'mvn clean package -Dmaven.test.skip=true'sh 'ls target/'echo "构建完成."// 演示怎样产生构建物script {def exists = fileExists "README.md"if (!exists) {writeFile(file: "README.md", text: "Helloworld")}}archiveArtifacts artifacts: "README.md", fingerprint: true// archiveArtifacts artifacts: "**/target/*.jar", fingerprint: true // 收集构建产物}}stage("测试") {steps {echo "单元测试中..."// 请在这里放置您项目代码的单元测试调用过程,例如:// sh "mvn test" // mvn 示例// sh "make test" // make 示例echo "单元测试完成."// 演示怎么样生成测试报告writeFile(file: 'TEST-demo.junit4.AppTest.xml', text: '''<testsuite name="demo.junit4.AppTest" time="0.053" tests="3" errors="0" skipped="0" failures="0"><properties></properties><testcase name="testApp" classname="demo.junit4.AppTest" time="0.003"/><testcase name="test1" classname="demo.junit4.AppTest" time="0"/><testcase name="test2" classname="demo.junit4.AppTest" time="0"/></testsuite>''')junit '*.xml'// junit "target/surefire-reports/*.xml" // 收集单元测试报告的调用过程}}stage("部署") {steps {echo "部署中..."script {// 您可以在此执行任意的 groovy 脚本def remote = [:]remote.name = 'VM-16-8-centos'remote.allowAnyHosts = trueremote.host = '106.55.34.215'remote.port = 22remote.user = 'root'withCredentials([sshUserPrivateKey(credentialsId: "66172def-3047-49e3-acbe-d14105375159",keyFileVariable: 'id_rsa')]) {remote.identityFile = "~/.ssh/id_rsa"// 读取的凭据将以环境的变量的形式获取 SSH_PRIVATE_KEY_PATH (SSH_PRIVATE_KEY_PATH 为私钥路径)//sshCommand remote: remote, sudo: true, command: "jps -ml | grep $DEPOT_NAME-*.jar"sshCommand remote: remote, sudo: true, command: "rm -rf /opt/$DEPOT_NAME-*.jar"sshPut remote: remote, from: "target/$DEPOT_NAME-${env.VERSION}.jar", into: "/opt/"sshCommand remote: remote, command: "nohup java -jar /opt/$DEPOT_NAME-${env.VERSION}.jar >/dev/null 2>&1 &"}}echo "部署完成"}}}}
