Skip to main content

GitLab CI/CD

Configuración básica

Crea archivo .gitlab-ci.yml en la raíz del proyecto:

stages:
- build
- test
- deploy

build:
stage: build
script:
- npm install
- npm run build
artifacts:
paths:
- dist/

test:
stage: test
script:
- npm test

deploy:
stage: deploy
script:
- echo "Deploying..."
only:
- main

Variables de entorno

  1. Ve a Settings > CI/CD > Variables
  2. Añade variables:
    • API_KEY: tu-api-key
    • DEPLOY_TOKEN: token-secreto
  3. Marca como Protected si solo main debe usarlas

Ejemplo: Deploy a servidor

deploy_production:
stage: deploy
script:
- apt-get update && apt-get install -y rsync
- rsync -avz --delete dist/ user@server:/var/www/app/
only:
- main
environment:
name: production
url: https://mi-app.com

Ejemplo: Docker build

docker_build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- docker build -t mi-app:$CI_COMMIT_SHA .
- docker push mi-app:$CI_COMMIT_SHA