Gitlab CI和R一起使用手动和手动规则

发布于 2025-02-06 18:50:23 字数 984 浏览 2 评论 0 原文

我正在尝试在gitlab中设置CI,因此

  1. 仅在 devjob 成功运行后,第二份工作( pushdev )才能手动运行。
  2. 第三个作业 PushTostage 只有在更改文件后才运行。

工作的方式,第二和第三个工作一直运行。管道规格中缺少什么

devjob:
  image: node:16
  stage: publishdev
  script:
    - echo "running validation checks"
    - npm run validate
  rules:
    - changes:
        - ./src/myfile.txt
    - when: manual


# - this jobs needs to run after "devjob" has run successfully
# and myfile.txt has changed
# - "needs" artifacts from the "lint" job 
pushdev:
  image: node:16
  stage: publishdev
  needs: [ "devjob", "lint"]
  script:
    - echo "Pushing changes after validation to dev"
    - npm run pushdev
  rules:
    - changes:
        - ./src/myfile.txt
      when: on_success
    - when: manual

pushtostage:
  image: node:16
  stage: pushstage
  script:
    - echo "Pushing changes to stage"
  rules:
    - changes:
        - ./src/myfile.txt
    - when: manual

I am trying to setup CI in gitlab so

  1. the second job (pushdev) will be available for running manually only after the devjob has run successfully.
  2. the third job pushtostage will only run iff file has changed.

the way the jobs are setup, second and third jobs alway run. What is missing in the pipeline spec

devjob:
  image: node:16
  stage: publishdev
  script:
    - echo "running validation checks"
    - npm run validate
  rules:
    - changes:
        - ./src/myfile.txt
    - when: manual


# - this jobs needs to run after "devjob" has run successfully
# and myfile.txt has changed
# - "needs" artifacts from the "lint" job 
pushdev:
  image: node:16
  stage: publishdev
  needs: [ "devjob", "lint"]
  script:
    - echo "Pushing changes after validation to dev"
    - npm run pushdev
  rules:
    - changes:
        - ./src/myfile.txt
      when: on_success
    - when: manual

pushtostage:
  image: node:16
  stage: pushstage
  script:
    - echo "Pushing changes to stage"
  rules:
    - changes:
        - ./src/myfile.txt
    - when: manual

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2025-02-13 18:50:23

我将您的样本更改为

stages:
  - publishdev
  - pushstage

default:
  image: ubuntu:20.04

lint:
  stage: publishdev
  script:
    - echo "lint job"

devjob:
  stage: publishdev
  script:
    - echo "running validation checks"
  rules:
    - changes:
        - README.md
      when: manual
      allow_failure: false

pushdev:
  stage: publishdev
  needs: [ "devjob", "lint"]
  script:
    - echo "Pushing changes after validation to dev"
  rules:
    - changes:
        - README.md
      when: manual
      allow_failure: false

pushtostage:
  stage: pushstage
  script:
    - echo "Pushing changes to stage"
  rules:
    - changes:
        - README.md
      when: manual
      allow_failure: false
  1. ​ci/yaml/#允许_failure“ rel =“ nofollow noreferrer”> allow_failure 当手动作业默认为真时。

  2. 我合并了您的规则。因为 gitlab规则一个 - 是一个规则:

当创建管道时,评估

规则,并按顺序进行评估。

您的.gitlab-ci.yml首先作业 devjob 是手动的,因此这始终是成功的,您的第二个作业 pushdev pushdev 第一个规则更改和 wher wher wher wher:on_success < /代码>始终匹配,因此它始终运行。

我更改您的.gitlab-ci.yml,第一个作业 devjob 在文件更改并设置它是手动作业而不允许_Failure时合并您的规则。等等。

I change your sample to look like this:

stages:
  - publishdev
  - pushstage

default:
  image: ubuntu:20.04

lint:
  stage: publishdev
  script:
    - echo "lint job"

devjob:
  stage: publishdev
  script:
    - echo "running validation checks"
  rules:
    - changes:
        - README.md
      when: manual
      allow_failure: false

pushdev:
  stage: publishdev
  needs: [ "devjob", "lint"]
  script:
    - echo "Pushing changes after validation to dev"
  rules:
    - changes:
        - README.md
      when: manual
      allow_failure: false

pushtostage:
  stage: pushstage
  script:
    - echo "Pushing changes to stage"
  rules:
    - changes:
        - README.md
      when: manual
      allow_failure: false
  1. I add allow_failure: false, because allow_failure when manual job default is true.

  2. I merge your rules. because GitLab rules one - is one rule:

Rules are evaluated when the pipeline is created, and evaluated in order until the first match.

your .gitlab-ci.yml first job devjob is manual, so it is always a success, and your second job pushdev first rule changes and when: on_success always match, so it always run.

I change your .gitlab-ci.yml, first job devjob merge your rules when file change and set it is manual job and not allow_failure. and so on.

the sample code in Files · try-rules-stackoverflow-72594854-manual · GitLab PlayGround / Workshop / Tryci · GitLab

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文