使用 extends 关键字的 GitLab Pipeline 错误

发布于 2025-01-11 09:59:04 字数 1739 浏览 0 评论 0原文

当我为存储库提交下一个 .gitlab-ci.yml 时,我在 GitLab Pipeline 上遇到错误。

  • 构建解决方案、部署到 Artifactory 以及触发和 API 调用所执行的管道
  • 部署作业必须手动执行,并且有两个不同的作业选项可以执行。

管道工作流程

stages:
  - build
  - deploy
  - trigger

variables:
    APP_PROJECT_ID: ${CUSTOMER_RELEASED}

build_job:
  stage: build
  tags:
    - dotnet
  script:
    - echo "build"
  only:
    - tags
  allow_failure: false

.deploy_job_base:
  stage: deploy
  needs: [build_job]
  tags:
    - dotnet
  script:
    - echo "deploy"
  dependencies:
    - build_job
  only:
    - tags

deploy_job_sport:
  extends: .deploy_job_base
  after_script:
    - $APP_PROJECT_ID = "2096"
  when: manual
  allow_failure: false

deploy_job_others:
  extends: .deploy_job_base
  after_script:
    - $APP_PROJECT_ID = "0"
  when: manual
  allow_failure: false

.trigger_base:
  stage: trigger
  script:
    - echo "Customer Project ID '{$APP_PROJECT_ID}'"
    - echo "Call API..."

trigger_sport:
  extends: .trigger_base
  needs: [deploy_job_sport]
  
trigger_others:
  extends: .trigger_base
  needs: [deploy_job_others]

Lint 状态正确 Lint 状态但是当我提交更改时,我收到了 GitLab Pipeline 错误:

在您的 .gitlab-ci.yml 中发现错误:“trigger_sport”工作需求 “deploy_job_sport”作业,但“deploy_job_sport”不在之前的任何作业中 阶段“trigger_others”作业需要“deploy_job_others”作业,但是 “deploy_job_others”不处于任何先前阶段

如果我删除trigger_sport和trigger_others作业并仅创建一个作业,它工作正常,但我不知道如何将两个手动作业(deploy_job_sport和deploy_job_others)定位到单个作业。 你有什么想法吗? 提前致谢。

I got an error on GitLab Pipeline when I commit the next .gitlab-ci.yml for a repository.

  • Pipeline executed to build solution, deploy to Artifactory and trigger and API call
  • Deploy job have to be executed manually, and there are two different job options to execute.

Pipeline WorkFlow

stages:
  - build
  - deploy
  - trigger

variables:
    APP_PROJECT_ID: ${CUSTOMER_RELEASED}

build_job:
  stage: build
  tags:
    - dotnet
  script:
    - echo "build"
  only:
    - tags
  allow_failure: false

.deploy_job_base:
  stage: deploy
  needs: [build_job]
  tags:
    - dotnet
  script:
    - echo "deploy"
  dependencies:
    - build_job
  only:
    - tags

deploy_job_sport:
  extends: .deploy_job_base
  after_script:
    - $APP_PROJECT_ID = "2096"
  when: manual
  allow_failure: false

deploy_job_others:
  extends: .deploy_job_base
  after_script:
    - $APP_PROJECT_ID = "0"
  when: manual
  allow_failure: false

.trigger_base:
  stage: trigger
  script:
    - echo "Customer Project ID '{$APP_PROJECT_ID}'"
    - echo "Call API..."

trigger_sport:
  extends: .trigger_base
  needs: [deploy_job_sport]
  
trigger_others:
  extends: .trigger_base
  needs: [deploy_job_others]

Lint status is correct
Lint Status
but I get that error GitLab Pipeline when I commit changes:

Found errors in your .gitlab-ci.yml: 'trigger_sport' job needs
'deploy_job_sport' job but 'deploy_job_sport' is not in any previous
stage 'trigger_others' job needs 'deploy_job_others' job but
'deploy_job_others' is not in any previous stage

If I remove trigger_sport and trigger_others job and create only one job, it works fine but I don't know how I can target the two manual jobs (deploy_job_sport and deploy_job_others) to a single job.
Do you have any idea?
Thanks in advance.

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

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

发布评论

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

评论(1

兮颜 2025-01-18 09:59:04

我认为这与您在模板中使用 only:tags 进行部署作业有关,并且构建作业也仅限于在提交包含 tag 时运行。

但是触发器模板缺少此限制,这很可能在推送没有标记的提交时导致此错误,因为管道创建会将 trigger_XY 添加到管道,该管道依赖于之前的 deploy_XY< /代码> 工作。

将触发器作业的作业模板更新为以下内容时,应解决此错误:

.trigger_base:
  stage: trigger
  script:
    - echo "Customer Project ID '{$APP_PROJECT_ID}'"
    - echo "Call API..."
  only:
    - tags

I think this is related to the fact that you're using only: tags in your template for deploy jobs and the build job also is limited to run when commits contain a tag.

But the trigger template is missing this limitation which most likely causes this error when pushing a commit without a tag because the pipeline creation would add trigger_XY to the pipeline, which has dependencies to the previous deploy_XY jobs.

When updating your job template for trigger jobs to the following this error should be resolved:

.trigger_base:
  stage: trigger
  script:
    - echo "Customer Project ID '{$APP_PROJECT_ID}'"
    - echo "Call API..."
  only:
    - tags
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文