1. 程式人生 > 其它 >CI/CD System and gerrit-trigger keypoints.

CI/CD System and gerrit-trigger keypoints.

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/

出處:http://www.cnblogs.com/lightsong/ 本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段宣告,且在文章頁面明顯位置給出原文連線。