作者:王耀 | 来源:互联网 | 2022-11-22 14:05
1> Rekovni..:
该before_script
语法不支持stages
section。您可以before_script
按本stages
节所述的方式使用,但是该before_script
阶段将针对管道中的每个作业运行。
相反,您可以做的是使用GitLab 锚的功能,该功能使您可以在.gitlab-ci
文件中复制内容。
因此,在您的情况下,它将类似于:
stages:
- security
- quality
- test
- build
- deploy
image: node:10.15.0
.before_script_template: &build_test-integration
before_script:
- apt-get update
- apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
- curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
- add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
- apt-get update
- apt-get -y install docker-ce
- curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- chmod +x /usr/local/bin/docker-compose
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
services:
- mongo
- docker:dind
security:
stage: security
script:
- npm audit
quality:
stage: quality
script:
- npm install
- npm run-script lint
test_unit:
stage: test
script:
- npm install
- npm run-script unit-test
test_integration:
stage: test
<<: *build_test-integration
script:
- docker-compose -f CI/backend-service/docker-compose.yml up -d
- npm install
- npm run-script integration-test
build:
stage: build
<<: *build_test-integration
script:
- npm install
- export VERSION=`git describe --tags --always`
- docker build -t $CI_REGISTRY_IMAGE:$VERSION .
- docker push $CI_REGISTRY_IMAGE
deploy:
stage: deploy
script: echo 'deploy'