我可以告诉 Gitlab-CI-job 从旧管道中检索工件吗?

Can I tell a Gitlab-CI-job to retrieve artifacts from an older pipeline?

我有一个 gitlab-ci 配置,看起来像这样:

simulate:
  stage: simulate
  when: manual
  script: 
    - "do simulation in matlab"
  artifacts:
    paths:
    - results/*.mat

 analyze:    
   stage: analyze
   script: 
     - "do analysis in matlab"
   dependencies:
     - simulate

   

analyze 作业需要来自 simulate 作业的工件。 但是,simulate 作业需要几个小时才能 运行,因此,我将其设为手动,因此它不会 运行 每次管道 运行s。 现状是:如果我不运行模拟,我就无法运行分析。 (如果没有模拟数据,分析就毫无意义。)

假设我没有更改模拟代码,只更改了分析代码。然后使用旧管道的工件 运行 analyze 作业会很方便。这可能吗?又如何?

您可以使用 dependencies 选项下载工件 或者您也可以使用 needs keyword.

您可以在您的代码中使用 needs 类似下面的内容:

simulate:
  stage: simulate
  when: manual
  script: 
    - "do simulation in matlab"
  artifacts:
    paths:
    - results/*.mat

 analyze:    
   stage: analyze
   needs: [simulate]
   script: 
     - "do analysis in matlab"

如果您要寻找的是能够在当前管道中使用早期管道的结果,那么您可能需要查看 CI 定义的 the cache directive,因为它们比工件更直观地在管道之间进行传递。

像这样:

simulate:
  stage: simulate
  when: manual
  script: 
    - "do simulation in matlab"
  cache:
    key: simulation-results
    policy: push
    paths:
    - results/*.mat

 analyze:    
   stage: analyze
   script: 
     - "do analysis in matlab"
   cache:
     key: simulation-results
     policy: pull
     paths:
     - results/*.mat

如果您拥有高级 Gitlab 许可证,您显然也可以 directly access the artifact using the CI_JOB_TOKEN,但如果您的管道偶尔运行,那在您的场景中可能用途有限,从那以后您可能必须调整 CI 在每个新的源数据管道之后进行相应的定义。