gitlab ci/cdの概要


gitlab ci/cd
CIとは?
開発者に自動化された継続的な統合
CI/CDパイプライン
パイプラインはJobsとStatesからなる
実行するタスクの定義:コードのコンパイルやテストなど
  • Stagesジョブを実行するタイミングを定義
  • JobはRunnerによって実行される.
    状態の複数のジョブを並列に実行
    Stage1 => Jobs1 => Jobs2 => Stage2
    ステージを正常に終了すると、パイプラインは次のステージに移動します.
    ステージ内のJobが失敗した場合、パイプラインは次のステージに移動せずに終了します.
    手動配置の設定
    パイプラインは自動的に実行できますが、配置時に手動で操作する必要があります.
    stages:
      - test
      - build
      - deploy
    
    test:
      stage: test
      script: echo "Running tests"
    
    build:
      stage: build
      script: echo "Building the app"
    
    deploy_staging:
      stage: deploy
      script:
        - echo "Deploy to staging server"
      only:
        - master
    
    deploy_prod:
      stage: deploy
      script:
        - echo "Deploy to production server"
      when: manual
      only:
        - master
    テストを実行します.たとえば、
  • テストユニットテスト
  • build dockerの場合、イメージが作成されます.
  • クバーネディスを配備しますが、配備を反映していますか?マージします.
  • whenオプション
  • alwaws
  • delayed
  • manual
  • never
  • on_failure
  • on_success
  • 手動ジョブ実行時の変数の設定
    stages:
      - build
      - test
      - deploy
    
    variables:    # 전역 변수
      NAME: 'assu'
    
    build-phase:      # 임의의 job 이름..
      stage: build
      tags:
        - ci-tag
      except:
        - dev
      before_script:
        - echo 'build-phase before script, except dev'
      script:
        - chcp 65001    # UTF-8 설정
        - echo 'build-phase script, except dev'
      after_script:
        - echo 'build-phase after_script, except dev'
    
    test-phase:      # 임의의 job 이름
      stage: test
      tags:
        - ci-tag
      except:
        - dev
      before_script:
        - echo 'build-phase before script, except dev'
      script:
        - chcp 65001    # UTF-8 설정
        - echo 'build-phase script, except dev' $NAME
      after_script:
        - echo 'build-phase after_script, except dev'
    
    deploy-phase:      # 임의의 job 이름
      stage: deploy
      tags:
        - ci-tag
      when: manual
      only:
        - master
      before_script:
        - echo 'deploy-phase before script, except dev'
      script:
        - chcp 65001    # UTF-8 설정
        - echo 'deploy-phase script, except dev'$NAME
      after_script:
        - echo 'deploy-phase after_script, except dev'
    パイプラインアーキテクチャ-基本
    パイプラインアーキテクチャ-直列ループパターン(DAG)
    *複雑なマイクロサービスを導入する場合に特に有効

    パイプラインアーキテクチャ-child/parent Pipeline
    rules
    job1:
      tags:
        - ci-tag
      stage: build
      script:
        - echo event
      rules:
        - if: '$CI_COMMIT_BRANCH == "master"'
          when: delayed
          start_in: '30 seconds'
          allow_failure: false
        - if: '$CI_COMMIT_BRANCH == "master22"'
          when: delayed
          start_in: '50 minutes'
          allow_failure: true
    job:
      script: "echo Hello, Rules!"
      rules:
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
          when: never
        - if: '$CI_PIPELINE_SOURCE == "schedule"'
          when: never
        - when: on_success
    workflow
    test => build => deploy
    
    test: unit, e2e 등 test 수행
    
    build: 도커 이미지 빌드 및 푸쉬