CI/CD Advance

gitlab duo chat

์งˆ๋ฌธ์ด ์žˆ์œผ๋ฉด duo chat์„ ์ด์šฉํ•˜์ž. ๋ฉ”๋‰ด๊ฐ€ ์ฐพ๊ธฐ ์–ด๋ ต๋‹ค. ์„œ๋น„์Šค์— ๋”ฐ๋ผ์„œ ์—†์„์ˆ˜๋„ ์žˆ๋‹ค.

duo chat

start pipeline

.gitlab-ci.yml ์ƒ์„ฑ (gitlab-ci.yaml์€ ๋™์ž‘ํ•˜์ง€์•Š์Œ)

  • stage

  • job

Alt text stage๊ฐ€ ์ƒ์„ฑ์ด ๋œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  job์ด ์ƒ์„ฑ์ด ๋œ๋‹ค.

stage๋Š” tagging system๊ณผ ๋น„์Šทํ•˜๋‹ค. ๋ชจ๋“ ๊ฒƒ์€ Job์œผ๋กœ ์›€์ง์ด์ง€๋งŒ stage๋Š” job์„ ๊ทธ๋ฃนํ™” ์‹œํ‚ค๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

script, before_script, and after_script

  • before_script: script์ „์— ์‹คํ–‰๋œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  script์™€ ๊ฐ™์€ shell์—์„œ ์‹คํ–‰๋œ๋‹ค.

  • script : runner์— ์˜ํ•ด์„œ ์‹คํ–‰๋œ๋‹ค. exitcode๋Š” ์—ฌ๊ธฐ์—์„œ ๋ฆฌํ„ด๋œ๋‹ค.

  • after_script : Runs in a separate shell after the before_script / script statements. (๋‹ค๋ฅธ ์‰˜์—์„œ ์‹คํ–‰๋œ๋‹ค. ) , exitcode ์— ๋Œ€ํ•ด์„œ๋Š” ์ƒ๊ด€ํ•˜์ง€ ์•Š๋Š”๋‹ค.

test์— ์ฝ”๋“œ ์ถ”๊ฐ€

์‹คํ–‰ ์ˆœ์œ„

stage ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰๋œ๋‹ค.

  • Jobs in the next stage will start after all jobs in the previous stage have completed successfully

  • ๋‹ค์Œ ๋‹จ๊ณ„์˜ ์ž‘์—…์€ ์ด์ „ ๋‹จ๊ณ„์˜ ๋ชจ๋“  ์ž‘์—…์ด ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋œ ํ›„ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค.

Alt text

GitLab Runners

type

  • SSH

  • Shell

  • Virtual Box

  • Parallels

  • Docker

  • Docker Autoscaler (Beta)

  • Docker Machine

  • Kubernetes

  • Custom

tag

tag๋ฅผ ์ด์šฉํ•ด์„œ runner๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋‹ค.

์‹คํ–‰ ์ˆœ์„œ ์ˆ˜์ •

need๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŠน์ • ์ž‘์—… ๋‹ค์Œ์— ์‹คํ–‰์„ ํ• ์ˆ˜ ์žˆ๋‹ค.

๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ stage๋ฅผ ๋™์‹œ์— ์‹คํ–‰ํ•˜๊ณ  ์‹ถ์„์ˆ˜ ์žˆ๋‹ค.

๋‘๊ฐœ์˜ ์žก์ด ๋‹ค๋ฅธ์žก์„ ๊ธฐ๋‹ค๋ฆฌ์ง€ ์•Š๊ณ  ๋™์‹œ์— ์‹คํ–‰๋œ๋‹ค.

Alt text

build๊ฐ€ ์•ˆ๋๋‚˜๋„ test๊ฐ€ ์‹คํ–‰๋œ๋‹ค. Alt text job dependencies๊ฐ€ ์ƒ๊ฒผ๊ณ  dependency๊ฐ€ ์—†๋Š”๊ฒƒ์„ ๋ณผ์ˆ˜ ์ž‡๋‹ค.

Directed Acyclic Graph

stage์ถ”๊ฐ€ํ•˜๊ณ  ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด์ž.

Alt text
Alt text

์—ฌ๊ธฐ์—์„œ ๋ณด๋ฉด ๋ณผ์ˆ˜ ์ž‡๋‹ค.

์›๋ณตํ•˜์ž.

Stageless Pipelines

๋ฒ„์ „์— ๋”ฐ๋ผ์„œ ๋‹ค๋ฅด์ง€๋งŒ ๊ธฐ์กด์—๋Š” need๋Š” ๋‹ค๋ฅธ stage์— job์— ์ ์šฉํ• ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

์ด์ œ๋Š” ๊ฐ™์€ stage์—์„œ๋„ need๊ฐ€ ์ ์šฉ๋จ. Allows โ€œneedsโ€ keyword to be used in the same stage

  • ํŒŒ์ดํ”„๋ผ์ธ์„ ์ข€๋” ํšจ๊ณผ์ ์œผ๋กœ ๋งŒ๋“ค์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์‹คํ–‰์ˆœ์„œ๋ฅผ ์ข€๋” ๋ช…ํ™•ํ•˜๊ฒŒ ์ •ํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Available in (All tiers; 14.2+)

Caching Basics

To cache, a GitLab Runner will take the content you cached and store it in GCP Cloud Storage

Cache Execution Order

  1. Pipeline starts.

  2. job A runs.

  3. before_script is executed.

  4. script is executed.

  5. after_script is executed.

  6. cache runs and the vendor/ directory is zipped into cache.zip. This file is then saved in the directory based on the runnerโ€™s setting and the cache: key.

  7. job B runs.

  8. The cache is extracted (if found).

  9. before_script is executed.

  10. script is executed.

  11. Pipeline finishes.

why cache?

์ž‘์—… ๊ฐ„์— ๋‹ค์šด๋กœ๋“œํ•œ ์ฝ˜ํ…์ธ  ๊ณต์œ : ์ฝ”๋“œ์˜ ์—ฌ๋Ÿฌ ๋ธŒ๋žœ์น˜์—์„œ ์ˆ˜ํ–‰ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ ์ข…์†์„ฑ ์ €์žฅ(๋‹ค์Œ์— ๋‹ค์šด๋กœ๋“œํ•  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆด ํ•„์š” ์—†์Œ) ํŒŒ์ดํ”„๋ผ์ธ ์†๋„ ํ–ฅ์ƒ

Alt text

hello.txt๋ฅผ ๋‹ค์Œ์ž‘์—…์ด ๋ฐ›์•„์„œ ์ฒ˜๋ฆฌํ• ์ˆ˜ ์žˆ๋‹ค.

hello world ๊ฐ€ ์ฐํžˆ๋Š”๊ฑธ ๋ณผ์ˆ˜ ์žˆ๋‹ค. ํŒŒ์ผ์„ ๊ฐ€์ ธ์™”๋‹ค๋Š” ๋œป์ด๋‹ค.

์ข€๋” ์˜๋ฏธ์ž‡๋Š” ์ƒ˜ํ”Œ์„ ํ•ด๋ณด์ž. ruby๋ฅผ ๋นŒ๋“œ๋ฅผ ๋จผ์ €ํ•ด์„œ ๊ทธ๊ฑธ ์บ์‹œํ•ด๋‘๊ณ  ๋‹ค์Œ์ž‘์—…์—์„œ ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๋‹ค.

์ข€๋” ์˜๋ฏธ์ž‡๋Š” ์ƒ˜ํ”Œ์„ ํ•ด๋ณด์ž. ruby๋ฅผ ๋นŒ๋“œ๋ฅผ ๋จผ์ €ํ•ด์„œ ๊ทธ๊ฑธ ์บ์‹œํ•ด๋‘๊ณ  ๋‹ค์Œ์ž‘์—…์—์„œ ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๋‹ค.

npm๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ด๋‹ค. ์ฒ˜์Œ๋ถ€ํ„ฐ ๋‹ค ์„ค์น˜ํ•˜์ง€ ์•Š๊ณ  ์„ค์น˜๋œ ํŒŒ์ผ๋“ค์„ ๋‹ค์šด๋ฐ›์€ํ›„ ์‚ฌ์šฉํ•˜๋ฉด ๋นŒ๋“œ ์‹œ๊ฐ„์„ ์ค„์ผ์ˆ˜ ์ž‡๋‹ค.

Allowing Job Failure (job ์‹คํŒจ๋ฅผ ํ—ˆ์šฉ)

We need to find a way to configure the pipeline so that even when the unit test job fails, subsequent jobs still execute.

๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž‘์—…์ด ์‹คํŒจํ•˜๋”๋ผ๋„ ํ›„์† ์ž‘์—…์ด ๊ณ„์† ์‹คํ–‰๋˜๋„๋ก ํŒŒ์ดํ”„๋ผ์ธ์„ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•

allow_failure: true - failing job is logged in the pipeline as failed, but does not prevent subsequent jobs from executing

allow_failure ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด๋œ๋‹ค.

์Šคํฌ๋ฆฝํŠธ exit 1 ์„ ์‹คํŒจ๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.

stage์— deploy๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.allow_failure: true ๊ฐ€ ์—†์œผ๋ฉด deploy๋Š” ์‹คํ–‰๋˜์ง€ ์•Š๋Š”๋‹ค.

allow_failure: true ์—†๋Š” ๊ฒฝ์šฐ Alt text

allow_failure: true ์žˆ๋Š” ๊ฒฝ์šฐ Alt text

rules

rules์„ ์ถ”๊ฐ€

๋งž๋Š” ์กฐ๊ฑด์—๋งŒ ์‹คํ–‰์ด ๋œ๋‹ค.

When is a Job NOT created in a Pipeline?

When is a Job NOT created in a Pipeline?

A job is not included in a pipeline if:

  • None of the rules defined for the job evaluate to true

  • A rule evaluates to true, but has clause of when: never

  • No rules are defined but a when: never clause is specified

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ ์ž‘์—…์€ ํŒŒ์ดํ”„๋ผ์ธ์— ํฌํ•จ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค:

  • ์ž‘์—…์— ๋Œ€ํ•ด ์ •์˜๋œ ๊ทœ์น™ ์ค‘ ์–ด๋А ๊ฒƒ๋„ ์ฐธ์œผ๋กœ ํ‰๊ฐ€๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

  • ๊ทœ์น™์ด ์ฐธ์œผ๋กœ ํ‰๊ฐ€๋˜์ง€๋งŒ when: never ์ ˆ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๊ทœ์น™์ด ์ •์˜๋˜์–ด ์žˆ์ง€ ์•Š์ง€๋งŒ when: never ์ ˆ์ด ์ง€์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋‘๊ฐœ์˜ ๊ฒฝ์šฐ์—๋Š” job์ด ์‹คํ–‰๋˜์ง€ ์•Š๋Š”๋‹ค.

when: on_success : ์ด์ „ ์ž‘์—…์ด ์„ฑ๊ณตํ–ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์—ฌ ์ž‘์—…์„ ์‹คํ–‰ํ•˜๋„๋ก ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค. ์ด์ค„์— ์˜ค๋ฉด ๊ธฐ์กด if๋Š” ์–ด๋А๊ฒƒ๋„ ๋งŒ์กฑํ•˜์ง€ ์•Š์„๋•Œ ์—ฌ๊ธฐ๊นŒ์ง€ ์˜ค๊ฒŒ ๋œ๋‹ค.

when: manual

์ˆ˜๋™์œผ๋กœ ์‹คํ–‰ํ•˜๊ณ  ์‹ถ์œผ๋ฉด when: manual ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋œ๋‹ค.

ํ™”๋ฉด์—์„œ ์‹คํ–‰๋ฒ„ํŠผ์ด ๋‚˜์˜ค๋ฏ€๋กœ ๊ทธ๊ฑธ ๋ˆ„๋ฅด๋ฉด๋œ๋‹ค.

click

If $CI_PIPELINE_SOURCE is set to merge_request_event or schedule, the job is executed

CI_PIPELINE_SOURCE๊ฐ€ merge_request_event ๋˜๋Š” ์Šค์ผ€์ค„๋กœ ์„ค์ •๋œ ๊ฒฝ์šฐ ์ž‘์—…์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

when for delaying a job run

If used as when: delayed, start_in is also required.

using changes and if

๊ฒฝ๋กœ์ค‘์— ํŒŒ์ผ์ด ๋ฐ”๊ท€๋ฉด ์‹คํ–‰๋˜๋„๋ก ํ• ์ˆ˜ ์žˆ๋‹ค.

์œ„ ๋‚ด์šฉ์€ ๋‘๊ฐœ์˜ ๊ฒฝ๋กœ์˜ ํŒŒ์ผ์ด ํ•˜๋‚˜๋ผ๋” ๋ฐ”๊ท€๋ฉด ์‹คํ–‰๋œ๋‹ค. AND๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ํ•˜๋ฉด๋œ๋‹ค.

variables Processing Order

The order of precedence for variables is (from highest to lowest): ๋ณ€์ˆ˜์˜ ์šฐ์„  ์ˆœ์œ„๋Š” (๋†’์€ ๊ฒƒ๋ถ€ํ„ฐ ๋‚ฎ์€ ๊ฒƒ) ์ž…๋‹ˆ๋‹ค

  1. CICD pipeline Trigger variables, scheduled pipeline variables, and manual pipeline run variables.

  2. Project-level variables or protected variables.

  3. Group-level variables or protected variables.

  4. Instance-level variables or protected variables.

  5. Inherited environment variables.

  6. YAML-defined job-level variables.

  7. YAML-defined global variables.

  8. Deployment variables.

  9. Predefined environment variables.

Alt text

Stroing with artifacts

Alt text

artifacts์„ ๋‹ค์šด๋กœ๋“œํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

template

How to get SAST from GitLab

SAST๋Š” Static Application Security Testing์˜ ์•ฝ์ž์ด๋‹ค.

add test stage

Now that we have SAST lets add a few more security templates to our project to confirm that our code is secure

Alt text

child process

SAST๋ฅผ ํ™œ์„ฑํ™”ํ•˜์—ฌ ํŒŒ์ดํ”„๋ผ์ธ์„ ๋ฐ๋ชจํ•œ ํ›„ ๋ณด์•ˆ ํŒ€์—์„œ ๋” ๋งŽ์€ ์Šค์บ๋„ˆ๋กœ ์ž์ฒด ํŒŒ์ดํ”„๋ผ์ธ์„ ์‹คํ–‰ํ•˜๊ณ  ์žˆ์œผ๋ฉฐ ์ด๋ฅผ ํŒŒ์ดํ”„๋ผ์ธ๊ณผ ํ†ตํ•ฉํ•˜๊ธฐ๋ฅผ ์›ํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ๋ ค์ค๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•œ ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•์€ ํ•˜์œ„ ํŒŒ์ดํ”„๋ผ์ธ์„ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด๋ผ๊ณ  ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

์ „์ฒด ์ฝ”๋“œ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜์ž.

new stage ์ถ”๊ฐ€

extra-security ์ถ”๊ฐ€. trigger๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  include๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

create folder and file

security-pipeline/security.gitlab-ci.yml

์–ด๋–ค ํŒŒ์ดํ”„๋ผ์ธ์ด๋ผ๋„ ์ถ”๊ฐ€ํ•ด์„œ ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๋‹ค.

Alt text

Downstream Pipelines

Two types:

  • Parent-child

    • ํŒŒ์ดํ”„๋ผ์ธ์ด ๊ฐ™์€ ํ”„๋กœ์ ํŠธ์— ์กด์žฌ

    • ๋ถ€๋ชจ ํŒŒ์ดํ”„๋ผ์ธ๊ณผ ๋™์ผํ•œ ํ”„๋กœ์ ํŠธ, ์ฐธ์กฐ ๋ฐ ์ปค๋ฐ‹ SHA์—์„œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

    • ๊ธฐ๋ณธ์ ์œผ๋กœ ํŒŒ์ดํ”„๋ผ์ธ์ด ์‹คํ–‰๋˜๋Š” ์ฐธ์กฐ์˜ ์ „์ฒด ์ƒํƒœ์— ์ง์ ‘์ ์ธ ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค(์ž์‹ ํŒŒ์ดํ”„๋ผ์ธ์„ ํŠธ๋ฆฌ๊ฑฐํ•  ๋•Œ strategy:depend๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ํ•œ).

    • ์ค‘์ฒฉ๋œ ๋ ˆ๋ฒจ 2๊ฐœ๋กœ ์ œํ•œ

  • Multi-project

    • ํŒŒ์ดํ”„๋ผ์ธ์€ ์—ฌ๋Ÿฌ ํ”„๋กœ์ ํŠธ์— ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

    • ์—…์ŠคํŠธ๋ฆผ(ํŠธ๋ฆฌ๊ฑฐ๋ง) ํŒŒ์ดํ”„๋ผ์ธ์€ ๋‹ค์šด์ŠคํŠธ๋ฆผ(ํŠธ๋ฆฌ๊ฑฐ๋ง) ํŒŒ์ดํ”„๋ผ์ธ์— ๋Œ€ํ•œ ์ œ์–ด ๊ถŒํ•œ์ด ๋งŽ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    • ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์ ํŠธ์˜ ์ „์ฒด ์ฐธ์กฐ ์ƒํƒœ์—๋Š” ์˜ํ–ฅ์„ ์ฃผ์ง€๋งŒ ํŠธ๋ฆฌ๊ฑฐ ํŒŒ์ดํ”„๋ผ์ธ์˜ ์ฐธ์กฐ ์ƒํƒœ์—๋Š” ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

    • ๋…๋ฆฝ์ ์ด๋ฏ€๋กœ ์ค‘์ฒฉ ์ œํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค.

Rules & Child Pipelines

Allows you to get creative and make dynamic changes to the current results of your pipelines ์ฐฝ์˜๋ ฅ์„ ๋ฐœํœ˜ํ•˜์—ฌ ํŒŒ์ดํ”„๋ผ์ธ์˜ ํ˜„์žฌ ๊ฒฐ๊ณผ๋ฅผ ๋™์ ์œผ๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Last updated

Was this helpful?