GitLab CI/CD

Tento navod vysvetluje, ako integrovat LoadFocus JMeter API klienta s GitLab CI/CD na automatizovane testovanie vykonnosti.

Kroky nastavenia

1. Ulozenie povereni ako premennych GitLab CI/CD

Najprv ulozte vase poverenia LoadFocus API ako premenne GitLab CI/CD:

  1. Prejdite na vas projekt GitLab
  2. Prejdite na Settings > CI/CD > Variables
  3. Pridajte nasledujuce premenne:
    • LOADFOCUS_API_KEY: Vas LoadFocus API kluc (oznacte ako "Masked")
    • LOADFOCUS_TEAM_ID: Vase LoadFocus team ID

2. Vytvorenie GitLab CI/CD pipeline

Vytvorte alebo aktualizujte vas subor .gitlab-ci.yml vo vasom repozitari:

stages:
- build
- test
- performance
- deploy
variables:
NODE_VERSION: "16"
build:
stage: build
image: node:${NODE_VERSION}
script:
- npm install
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 week
test:
stage: test
image: node:${NODE_VERSION}
script:
- npm install
- npm test
performance_test:
stage: performance
image: node:${NODE_VERSION}
script:
- npm install -g @loadfocus/loadfocus-api-client
- loadfocus-api config set apikey $LOADFOCUS_API_KEY
- loadfocus-api config set teamid $LOADFOCUS_TEAM_ID
- |
loadfocus-api jmeter run-test \
--name "GitLab_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}" \
--thresholds "avgresponse<=200,errors==0,p95<=250" \
--format json > performance_results.json
artifacts:
paths:
- performance_results.json
expire_in: 1 week
when: always
only:
- main
- develop
deploy:
stage: deploy
script:
- echo "Deploying application..."
only:
- main
when: on_success

3. Zobrazenie vysledkov testov

Po behu pipeline:

  1. Prejdite na vas projekt GitLab
  2. Prejdite na CI/CD > Pipelines
  3. Najdite vas pipeline a kliknite nan
  4. Prejdite na ulohu "performance_test"
  5. Kliknite na "Browse" v pravom paneli na zobrazenie artefaktov
  6. Stiahnite a zobrazte subor performance_results.json

Tipy pre integraciu GitLab CI/CD

  1. Cachovanie: Cachujte npm zavislosti na zrychlenie behov pipeline.

  2. Nastavenia casoveho limitu: Nastavte casove limity pre dlhotrvajuce testy vykonnosti:

    performance_test:
    stage: performance
    image: node:${NODE_VERSION}
    timeout: 2h
    script:
    # Performance test script...
  3. Manualne spustace: Povolte manualne spustenie testov vykonnosti:

    performance_test:
    stage: performance
    image: node:${NODE_VERSION}
    script:
    # Performance test script...
    when: manual
  4. Notifikacie: Posielajte notifikacie pri zlyhaniach testov vykonnosti.

Pre viac informacii pozrite dokumentaciu GitLab CI/CD a dokumentaciu LoadFocus API klienta.