在Ubuntu上配置GitLab的CI/CD,可按以下步驟進行:
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
。sudo apt-get install gitlab-runner
。sudo gitlab-runner register --url https://gitlab.com/ --token "YOUR_REGISTRATION_TOKEN"
,按提示填寫描述、標簽、執行器等信息。.gitlab-ci.yml
文件在項目根目錄下創建該文件,定義CI/CD流程,如:
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- echo "Building the project..."
- npm install
- npm run build
test_job:
stage: test
script:
- echo "Running tests..."
- npm test
deploy_job:
stage: deploy
script:
- echo "Deploying the project..."
- scp build/* user@server:/path/to/deploy
only:
- master
將.gitlab-ci.yml
文件提交并推送到GitLab倉庫,GitLab Runner會自動檢測并執行定義的任務,可在GitLab的“CI/CD”→“Pipelines”頁面查看狀態和日志。