[英]Gitlab-ci : How to reach dayli automated tests and manual deploying
所以我有這個Angular 6 / Material 6應用程序,並且我在它周圍建立了一個gitlab來處理連續集成。
我不確定如何處理所需的處理:我主要需要兩個階段:測試和部署
此刻我得到了這個conf:
image: node:8.9.4
stages:
- test
- deploy
cache:
paths:
- node_modules/
before_script:
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Starting before scripts commands'
- apt-get update -qq && apt-get install -y -qq sshpass
- apt-get --yes install npm
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Setting registry to point verdaccio'
- npm set registry http://192.168.1.20:4873/
- echo [`date "+%d/%m/%y %H:%M:%S"`] '//192.168.1.20:4873/:_authToken=${NPM_TOKEN}'>.npmrc
- apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Installing all project libs'
- npm install
# ********************************************* TESTS STAGE *********************************************
test_stage:
stage: test
environment: Staging
script:
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Starting script part for test_stage'
- npm install
- ./node_modules/.bin/ng test --karma-config=karma.conf.js --watch=false
only:
- master
- triggers
# You want a cron to trigger the test build :
# Include this line to crontab :
# 0 4 * * * curl -X POST -F token=FOUND_IN_GITLAB -F ref=master -F "variables[IF YOU WANT SOME]=true" http://GITLAB_URL/api/v3/projects/PROJECT_NUMBER/trigger/builds
# Get token in in gitlab section Triggers
# Get PROJECT _NUMBER in gitlab section Triggers
except:
- pushes
# ********************************************* DEPLOY STAGE *********************************************
deploy_stage:
stage: deploy
environment: Staging
only:
- master
script:
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Starting script part for deploy_stage'
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Compiling with NG BUILD'
- ./node_modules/.bin/ng build --configuration=recette --prod
- sshpass -V
- export SSHPASS=$USER_PASS
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Deleting everything in archive folder'
- sshpass -e ssh -o StrictHostKeyChecking=no USER@XX.XX.XX.XX -pPORT "rm -rf /CHEMIN_ARCHIVE/archive/*"
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Copying server files into archive folder'
- sshpass -e ssh -o StrictHostKeyChecking=no USER@XX.XX.XX.XX -pPORT "cp -a /CHEMIN_SERVER/server/. /CHEMIN_ARCHIVEt/archive/"
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Deleting everything in server folder'
- sshpass -e ssh -o StrictHostKeyChecking=no USER@XX.XX.XX.XX -pPORT "rm -rf /CHEMIN_SERVER/server/*"
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Sending dist folder to livraison folder'
- sshpass -e scp -P PORT -o StrictHostKeyChecking=no -r ./dist USER@XX.XX.XX.XX:/CHEMIN_LIVRAISON/livraison
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Copying livraison files to server folder'
- sshpass -e ssh -o StrictHostKeyChecking=no USER@XX.XX.XX.XX -pPORT "cp -a /CHEMIN_LIVRAISON/livraison/. /CHEMIN_SERVER/server/"
- echo -e [`date "+%d/%m/%y %H:%M:%S"`] '\E[0;36m=======> Deleting everything in livraison folder'
- sshpass -e ssh -o StrictHostKeyChecking=no USER@XX.XX.XX.XX -pPORT "rm -rf /CHEMIN_LIVRAISON/livraison/*"
when: manual
但正如您所看到的,何時:手冊正在工作。 意味着cron觸發了構建,它進入了Tests階段,然后跳過了部署階段:
當然,按照計划,我可以手動觸發此部署階段,但隨后不會觸發測試。
因此,我該如何到達目標:當我手動觸發部署構建時,如果可以運行測試,並且如果測試失敗,則應該啟動部署,那就太好了嗎?
非常感謝。
這是一個可能的解決方案:
stages:
- test
- deploy
.test-template: &test-definition
image: alpine:3.6
stage: test
script:
- bash launch_test.sh
trigger-test:
<<: *test-definition
only:
- triggers
manual-test:
<<: *test-definition
when: manual
only:
- master
allow_failure: false
deploy:
image: alpine:3.6
stage: deploy
script:
- bash deploy.sh
only:
- master
dependencies:
- manual-test
您手動啟動手動manual-test
作業,如果成功,則啟動deploy
作業。
您還可以觸發trigger-test
以僅啟動測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.