簡體   English   中英

Gitlab:如果作業失敗,工件不會傳遞到子管道

[英]Gitlab: artifacts don't pass to child pipeline if job fails

如果某些作業失敗,如何從父管道中的作業傳遞工件?

有我的 CI:

 .run-tests:
  image: maven-allure:jdk-15
  before_script:
    - apt-get update && apt-get install -y gettext-base
    - envsubst < ci-settings.xml > settings.xml
  artifacts:
    name: "${CI_PROJECT_NAME}-${CI_COMMIT_REF_SLUG}"
    paths:
      - mvn_log*
      - target*
    expire_in: 3 days
    when: always
  tags:
    - k8s

  smoke-tests:
  stage: smoke tests
  extends:
    - .run-tests
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "push"
      when: never
    - if: $CI_PIPELINE_SOURCE == "web"
      when: always
  script:
    - *smoke-tests

  sanity-tests:
  stage: sanity tests
  extends:
    - .run-tests
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "push"
      when: never
    - if: $CI_PIPELINE_SOURCE == "web"
      when: always
  script:
    - *sanity-tests
  
  patient-api-tests:
  stage: api tests
  extends:
    - .run-tests
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "push"
      when: never
    - if: $CI_PIPELINE_SOURCE == "web"
      when: manual
  variables:
    TELEGRAM_USER_ID: "xxxx"
  script:
    - *patient-api-tests
  needs: []
  
  patient-api-tests-trigger:
  stage: trigger jobs
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule" || $CI_PIPELINE_SOURCE == "push"
      when: never
    - if: $CI_PIPELINE_SOURCE == "web"
      when: always
  needs: ["patient-api-tests"]
  trigger:
    include: .trigger-ci.yml
    strategy: depend
    forward:
      yaml_variables: true
      pipeline_variables: true
  variables:
    PARENT_JOB_NAME: $CI_JOB_NAME
    PARENT_PIPELINE_ID: $CI_PIPELINE_ID

  .upload-report:
  image: maven-allure:jdk-15
  variables:
    TELEGRAM_USER_ID: "xxx"
  script:
    - apt-get update && apt-get install -y gettext-base jq curl
    - envsubst < ci-settings.xml > settings.xml
    - cp -f settings.xml /usr/share/maven/conf/settings.xml
    - mkdir -p target/allure-results
    - mv target_*/allure-results/* target/allure-results
    - mvn allure:report
    - date
    - sh upload.sh
  tags:
    - k8s

  upload-sanity-smoke-report:
  extends: .upload-report
  stage: upload smoke sanity report (on failed)
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
      when: never
    - if: $CI_PIPELINE_SOURCE == "web"
      when: always
      allow_failure: true
  needs: ["smoke-tests", "sanity-tests"]

upload-patient-report:
  extends: .upload-report
  stage: upload api report (always)
  rules:
    - if: $CI_PIPELINE_SOURCE == "schedule"
      when: never
    - if: $CI_PIPELINE_SOURCE == "parent_pipeline" && $PARENT_JOB_NAME == "patient-api-tests-trigger"
      when: always
  before_script:
    - echo $PARENT_PIPELINE_ID
  needs:
    - pipeline: $PARENT_PIPELINE_ID
      job: sanity-tests
    - pipeline: $PARENT_PIPELINE_ID
      job: smoke-tests
    - pipeline: $PARENT_PIPELINE_ID
      job: patient-api-tests

如果某些作業失敗,作業上傳患者報告無法以錯誤開始:

This job could not start because it could not retrieve the needed
artifacts.

也許您知道如何在不需要的情況下在子管道中獲取工件? I already tried to curl API artifacts by link like: https://gitlab.ru/api/v4/projects/${CI_PROJECT_ID}/jobs/artifacts/${CI_COMMIT_REF_NAME}/download?job=smoke-tests And that way don '不能在 CI 中工作,我不知道為什么,我剛剛收到 404 錯誤。 但在 CLI 工件是下載

通過擁有圖形管道,我也遇到了這個問題。 但是,如果不指定needs關鍵字,在這種情況下就無法傳遞工件。

您可以為needs項目指定optional參數

needs:
  - job: "jobname"
    pipeline: $PARENT_PIPELINE_ID
    optional: true

您還可以通過將父管道配置為 (1) 在觸發子管道之前完成所需的作業和 (2)指定artifacts:when:使上游作業always為來幫助確保作業可以檢索工件。

另請參閱文檔,特別注意 [un] 支持的場景(例如,合並結果管道不支持此功能)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM