Gitlab中Pipeline语法二

Gitlab中Pipeline语法

tags/allow_failure/when/retry/timeout/parallel

tags

用于指定不同的job在指定的runner上运行

allow_failure

允许作业失败,默认false,若果为true表示所在作业(job)失败不会阻塞后续作业(job).

when

  • on_success 前面阶段中所有作业都成功才会执行,默认值
  • on_failure 当前面阶段出现失败时执行
  • always 总是执行作业
  • manual 手动执行作业
  • delayed 延迟执行作业.配合start_in:10,表示延迟10s执行
before_script:
  - echo "before_script!!!"

variables:
  DOMAIN: example.com

stages:
  - build
  - test
  - codescan
  - deploy

build:
  before_script:
    - echo "before_script in build job"
  stage: build
  script:
    - echo "mvn clean"
    - echo "mvn install"
    - echo "$DOMAIN"
  after_script:
    - echo "after_script in build job"
  allow_failure: true
 
unittes:
  stage: test
  script:
    - ech "run test"
  when: delayed
  start_in: "10"
  allow_failure: true

deploy:
  stage: deploy
  script:
    - echo "hello deploy"
    - sleep 2;
  when: manual
  
codescan:
  stage: codescan
  script:
    - echo "codescan"
    - sleep 5;
  when: on_success
 
after_script:
  - echo "after_script"

Gitlab中Pipeline语法二_第1张图片

retry

配置失败的情况下重试作业的次数,只能>=0并且<=2.
retry重试精确匹配错误
max:最大重试次数,when:重试失败的错误类型.
always:在发什任何故障时重试(默认值);
unknown_failure:当失败原因未知时.
script_failure: 脚本失败时重试
api_failure: API失败时重试
stuck_or_timeout_failure: 作业卡主或超时重试.
runner_system_failure: 运行系统发生故障时重试.
missing_dependency_failure: 依赖丢失时
runner_unsupported: runner不受支持时
stale_schedule: 无法执行延迟的作业
job_execution_timeout: 脚本超出了为作业设置的最大执行时间时
archived_failure: 作业已存档且无法运行时
unmet_preequisites: 作业未能完成先决条件任务时
scheduler_failure: 调度程序未能将作业分配给运行的scheduler-failure时
data_integrity_failure: 检测到结构完整性问题时

unittest:
  stage:test
  tags:
    - build
  only:
    - master
  script:
    - ech "run"
  retry:
    max: 2
    when:
      - script_failure

Gitlab中Pipeline语法二_第2张图片

timeout

作业超时,作业超时可以超过项目级超时,但补能超过Runner特定的超时时间

buld:
  script:
    - echo "build"
  timeout: 3 hours 10 minutes

test:
  script:
    - echo "test"
  timeout: 3h 10m

parallel

并行作业,配置要并行运行的作业实例数,必须>=2并且<=50

codescan:
  stage: codescan
  tags:
   - build
  only:
    - master
  script:
    - echo "codescan"
    - sleep 3;
  parallel: 5

Gitlab中Pipeline语法二_第3张图片

你可能感兴趣的:(gitlab,linux)