gitlab--needs、default

简介: gitlab--needs、default

needs 并行阶段


可无序执行作业,无需按照阶段顺序运行某些作业,可以让多个阶段同时运行

例如下面的 ci 文件

stages:
  - build
  - test
  - deploy
module-a-build:
  stage: build
  script: 
    - echo "hello3a"
    - sleep 10
module-b-build:
  stage: build
  script: 
    - echo "hello3b"
    - sleep 10
module-a-test:
  stage: test
  script: 
    - echo "hello3a"
    - sleep 10
module-b-test:
  stage: test
  script: 
    - echo "hello3b"
    - sleep 10

运行上面的流水线

但现在我们可能需要,当 module-a-build 运行完成之后就运行 module-a-test,当 module-b-build 运行完成之后运行 module-b-test。这时候就需要 needs 了

修改 ci 文件,修改后的如下

stages:
  - build
  - test
module-a-build:
  stage: build
  script: 
    - echo "hello3a"
    - sleep 10
module-b-build:
  stage: build
  script: 
    - echo "hello3b"
    - sleep 30
module-a-test:
  stage: test
  script: 
    - echo "hello3a"
    - sleep 10
  needs: ["module-a-build"] # 当 module-a-build 运行完成之后就运行 module-a-test
module-b-test:
  stage: test
  script: 
    - echo "hello3b"
    - sleep 10
  needs: ["module-b-build"] # 当 module-b-build 运行完成之后就运行 module-b-test

运行流水线

可以查看作业依赖项

点击依赖关系图也可以看到


制品下载


在使用needs,可通过artifacts: trueartifacts: false来控制工件下载。 默认不指定为 true,表示下载制品

module-a-test:
  stage: test
  script: 
    - echo "hello3a"
    - sleep 10
  needs: 
    - job: "module-a-build"
      artifacts: true # 会下载 module-a-build 产生的制品


default


使用 default 可以定义每个 job 的参数,如果 job 里有,会覆盖 default 里的,例如下面的代码

default: # 定义了一个默认的参数
  tags: # 如果 job 里没有 tages,就使用这个 tags
    - build
  retry: # 如果 job 里没有 retry,就使用这个 tags
    max: 2
  before_script: # 如果 job 里没有 before_script,就使用这个 tags
    - echo "before_script"
stages:
  - build
  - test
build:
  stage: build
  before_script:
    - echo "我是 job 里的"
  script:
    - echo "我是 build 的 job"
test:
  stage: test
  script:
    - echo "test 的 job"

运行流水线,查看 build 的日志

在来看下 test


相关文章
|
7月前
|
Linux Docker Windows
docker pull 报错解决:error pulling image configuration: Get https:..
docker pull 报错解决:error pulling image configuration: Get https:..
320 0
|
4月前
|
安全 Linux 数据安全/隐私保护
docker运行报错docker: Error response from daemon: AppArmor enabled on system but the docker-default prof
docker运行报错docker: Error response from daemon: AppArmor enabled on system but the docker-default prof
82 0
|
1天前
|
Java Linux 数据库
改default client等小技巧
改default client等小技巧
|
5月前
|
Dubbo 应用服务中间件
【Default config not found for ApplicationConfig】的一种解决方案
【Default config not found for ApplicationConfig】的一种解决方案
118 0
|
6月前
no module nameed frontend
no module nameed frontend
24 0
|
6月前
|
Java Spring
Spring Boot 启动报错解决:No active profile set, falling back to default profiles: default
Spring Boot 启动报错解决:No active profile set, falling back to default profiles: default
121 0
|
9月前
|
开发工具 git
gitlab--workflow、rules
gitlab--workflow、rules
|
Docker 容器
解决Using default tag: latest Got permission denied while trying to connect to the Docker daemon socke
解决Using default tag: latest Got permission denied while trying to connect to the Docker daemon socke
297 0
Perhaps you should add the directory containing libpcre.pc to the PKG_CONFIG_PATH
Perhaps you should add the directory containing libpcre.pc to the PKG_CONFIG_PATH
101 0
|
Kubernetes 数据库连接 Nacos
在minikube中启动ruoyi-modules-system
在minikube中启动ruoyi-modules-system
在minikube中启动ruoyi-modules-system