运维-gitlab-CICD-语法2

172 阅读2分钟

语法1:tags

explain: 用于从运行运行该项目的所有Runner列表中选择特定的Runner

example:

job1:
    stage:
    - build
    tags:
    - deploy
    script:
    - echo "Hello!"

语法2:allow_failure

explain: allow_failure允许作业失败,默认值为false。启用后,如果作业失败,该作业将在用户界面中显示橙色警告。但是,管道的逻辑流程将认为作业成功/通过,并且不会被阻塞。(如下图)

image.png

example:

job1:
    stage: test
    script:
        - echo "hello world!"
    allow_failure: true

语法3:when

explain: 控制作业的运行

  • on_success 前面阶段中的所有作业都成功时才执行作业,默认值。
  • on_failure 当前面阶段出现失败时执行。
  • always 总是执行作业
  • manual 手动执行作业
  • delayed 延迟执行作业

example:

pipeline:

image.png

效果图:

image.png

语法4:retry

explain:

配置在失败的情况下重试作业的次数。

example:

job:
    stage: test
    script:
        - ech "run test"
    allow_failure: faile
    retry: 2

重试原因:

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_prerequisites:作业未能完成先决条件任务。
scheduler_.failure:调度程序未能将作业分配给运行scheduler_failure。
data_integrity_failure:检测到结构完整性问题。

语法4:timeout

explain:

作业级别的超时可以超过项目级别超时,但不能超过Runner特定的超时。

example:

build:
    script: echo "hello world"
    timeout: 3 hours 30 minutes

语法5:paralled

explain:

配置要并行运行的作业实例数,此值必须大于或等于2并且小于或等于50. 这将创建N个并行运行的同一作业实例.它们从job_name 1/N到job_name N/N依次命名。

example:

deploy:
    script: echo "hello world"
    paralled: 5

image.png