본문 바로가기

개발 도구/Bitbucket

[ Bitbucket ] Pipeline 설정하기

반응형

 

 

Bitbucket Pipelines는 Bitbucket Cloud에서 CI/CD를 구현할 수 있는 기능으로, .bitbucket-pipelines.yml 파일에 파이프라인 설정을 정의합니다.
아래는 일반적인 Bitbucket Pipelines 설정 예시와 구성 요소 설명입니다:


📄 기본 .bitbucket-pipelines.yml 예제

image: node:18

pipelines:
  default:
    - step:
        name: Build and Test
        caches:
          - node
        script:
          - npm install
          - npm run test

🔍 주요 구성 요소 설명

항목 설명

image Docker Hub에서 사용할 베이스 이미지를 지정합니다. 예: node:18, python:3.10, ubuntu, 등
pipelines 파이프라인 정의의 루트 노드로, 다양한 트리거(기본, 브랜치, 태그, pull-requests 등)에 따라 작업을 정의
default 기본 파이프라인. 아무 조건 없이 커밋되면 실행되는 파이프라인
step 각 파이프라인의 작업 단위. 여러 개의 step을 정의할 수 있으며 순차 실행됨
name (선택사항) step 이름을 지정. UI에 표시됨
caches node, pip, composer 등 캐시 키워드를 사용해 종속성 설치 시간 단축
script 실제로 실행될 쉘 명령어 목록 (리스트 형태로 작성)

✅ 다른 트리거 예시

pipelines:
  branches:
    main:
      - step:
          name: Deploy to Production
          script:
            - ./deploy.sh prod

  pull-requests:
    '**':
      - step:
          name: Lint and Test on PR
          script:
            - npm install
            - npm run lint
            - npm run test
  • branches: 특정 브랜치에 push될 때만 실행
  • pull-requests: PR 생성 시 실행 ('**'는 모든 브랜치를 의미)

📌 고급 기능

기능 예시 설명

조건부 실행 branches, tags, pull-requests 조건에 따라 다른 파이프라인을 실행
병렬 실행 여러 step을 parallel로 설정 빌드 시간 단축
환경변수 deployment: staging, services: 등과 함께 사용 환경별 배포 정의 가능
캐시 caches: 키워드로 디펜던시 캐싱 성능 향상

 

반응형