首页 > 解决方案 > Gitlab/CI 作业规则评估

问题描述

我正在尝试根据上一个作业的结果跳过 GitLab ci 作业,但是,因此,该作业永远不会运行。我的印象是规则是在流水线开始而不是在作业开始时评估的。有什么办法让它工作吗?

cache:
  paths:
  - .images

stages:
  - prepare
  - build

dirs:
  stage: prepare
  image:
    name: docker.image.me/run:latest
  script:
    - rm -rf .images/*
    - [ $(($RANDOM % 2)) -eq 1 ] && touch .images/DESKTOP

desktop:
  stage: build
  needs: ["dirs"]
  image:
    name: docker.image.me/run:latest
  rules:
    - exists:
        - .images/DESKTOP
      when: always
  script: 
    - echo "Why is this never launched?"

标签: gitlab-ci

解决方案


动态创建的工作可能是一种解决方案(https://docs.gitlab.com/ee/ci/parent_child_pipelines.html#dynamic-child-pipelines)。

如果创建了“.images/DESKTOP”,您可以在“dirs”-job 的“script”部分创建一个带有“desktop”-job 的 yml 文件。否则您创建的 yml 文件应该是空的。

创建的 yml 文件可以在“dirs”-job 之后的单独作业中触发。

我用于创建动态子管道 jsonnet ( https://jsonnet.org/ )。


推荐阅读