CI/CD System
https://www.redhat.com/en/topics/devops/what-is-ci-cd#ci/cd-tools
CI关注开发阶段
CD -- Delivery 对应版本的自动化发布, 发布到制品库, 但是部署可能后续为手动
CD -- Deployment 包括版本的自动化发布, 同时也包括自动化部署
https://www.geeksforgeeks.org/what-is-ci-cd/
面向开发者的CI过程
面向版本的 CD / CD 过程
CI输出的结果,需要进行 ACC 测试, 然后打包到制品库。
CD 选定待部署的版本之后, 部署到产品环境, 需要进行 冒烟测试。
Gerrit-Trigger
https://plugins.jenkins.io/gerrit-trigger/
开发者提交代码,未何如库之前, 进行模块单元等测试 --- 对应 Patchset Created事件
开发者提交代码, 何如库之后, 需要进行模块功能测试 --- 对应 Change Merged事件
版本确定,使用 git tag打上版本号, 需要进行版本测试(ACC测试) --- 对应 Ref Updated事件
https://reviews.mahara.org/Documentation/config-hooks.html#_ref_updated
Gerrit Code Review - Hooks
各种事件说明
Code Sample --- FOR COMMIT CI
https://github.com/berniehuang/autotest/blob/9384b5cbe13a71e12fddfe952cd9c4e275917eeb/Jenkinsfile
pipeline { agent any triggers { gerrit( serverName: 'gerrit.office.iauto.com', gerritProjects: [[ compareType: 'PLAIN', pattern: 'All-Users', branches: [[ compareType: 'PLAIN', pattern: 'master' ]] ]], triggerOnEvents: [ changeMerged(), patchsetCreated(excludeDrafts: false, excludeNoCodeChange: false, excludeTrivialRebase: false) ] ) } stages { stage('Install') { when { expression { BUILD_EXPRESSION } } steps { echo 'Good' } } stage('Build') { parallel { stage('build') { steps { echo 'Hello World' sh 'ls -l' } } stage('deploy') { steps { echo 'deploy' sh 'pwd' } } stage('compile') { steps { echo 'compile' sh 'echo $PATH' } } } } stage('Run') { parallel { stage('Run') { steps { echo 'running' timestamps() } } stage('Startup') { steps { echo 'startup' } } } } stage('Test') { steps { echo 'test' } } stage('Mail') { steps { mail(subject: 'Test', body: 'hello') sh 'ls -l' echo 'send mail' } } } environment { BUILD_EXPRESSION = false } }
Code Sampe --- for CRON
https://github.com/Hiristic/Jenkins-global-lib/blob/717996ab3b327f0bfcd6386bc760289830477c16/jenkinsfiles/Demo/demo-28-Triggers.groovy
//This is how to handle faults in stages and on pipeline level pipeline { agent {label 'master'} triggers { // On Gerrit patchset creation //gerrit customUrl: '', gerritProjects: [[branches: [[compareType: 'REG_EXP', pattern: '.*']], compareType: 'PLAIN', disableStrictForbiddenFileVerification: false, pattern: '.*']], serverName: 'gerrit', triggerOnEvents: [patchsetCreated()] // On changes in Git repo. Can be used if Gerrit is not available or due to lazyness //pollSCM '* * * * *' //Every minute //cron{"* * * * *"} //Conditional cron //cron(JENKINS_URL.contains("jenkins-staging") ? "@daily" : "") //cron(JENKINS_URL.contains("jenkins-production") ? "H 0-7 * * *" : "") // After others jobs are done upstream 'demo-00-base-structure' } stages { stage('On master') { steps { script { cleanWs() echo "Build started: "+RUN_DISPLAY_URL echo "Running" } } } } }
TAG EVENT LISTEN
https://stackoverflow.com/questions/29742847/jenkins-trigger-build-if-new-tag-is-released?noredirect=1&lq=1
Set refspec to:
+refs/tags/*:refs/remotes/origin/tags/*
branch specifier:
**
https://stackoverflow.com/questions/54930947/groovy-job-dsl-for-triggering-jenkins-based-on-new-release-tags?rq=1
checkout([$class: 'GitSCM', branches: [[name: '**']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'yourAuthHere', refspec: '+refs/tags/*:refs/remotes/origin/tags/*', url: 'yourGitRepoLocationHere']]])
GIT TAGGED PROJECT
https://github.com/oleg-nenashev/demo-jenkins-config-as-code/tags
GIT TAG BASIC
https://git-scm.com/book/en/v2/Git-Basics-Tagging
https://www.toolsqa.com/git/github-tags/