gpt4 book ai didi

devops - 在 Gitlab-ci 中,有一种方法仅在规则匹配后才在脚本之前运行

转载 作者:行者123 更新时间:2023-12-03 08:05:39 25 4
gpt4 key购买 nike

在 gitlab-ci 中我有

before_script:
- apt update && apt upgrade -y
- apt install -y

在我的舞台工作中我添加了一条规则

merge_request:
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "master"
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "master"

发生的情况是,当之前的脚本运行时,该作业在他的阶段被触发,然后它到达规则并发现没有什么可做的。这会减慢管道速度。有没有办法在“before_script”之前添加规则

这是管道 pipeline谢谢

最佳答案

找到答案here

.before_script_template:
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

test_integration:
extends: .before_script_template
stage: test
script:
- docker-compose -f CI/backend-service/docker-compose.yml up -d
- npm install
- npm run-script integration-test

build:
extends: .before_script_template
stage: build
script:
- npm install
- export VERSION=`git describe --tags --always`
- docker build -t $CI_REGISTRY_IMAGE:$VERSION .
- docker push $CI_REGISTRY_IMAGE

etc

关于devops - 在 Gitlab-ci 中,有一种方法仅在规则匹配后才在脚本之前运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72457620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com