Gitlab:通过工作和阶段传递人工制品

时间:2019-01-23 12:49:39

标签: node.js gitlab mocha gitlab-ci

我使用node.js摩卡和selenium-webdriver进行e2e测试。 我有不同的阶段,例如安装,测试按钮1,测试按钮2。 每个阶段(安装除外)都有2个工作(用于chrome和safari)。 我的目标是最终获得1个txt文件,其中包含各个阶段所有作业的测试结果。

我尝试了许多不同的配置:

  1. 始终传递工件report.txt并在每个作业中运行./mocha >> report.txt。
    • 导致文件中的数据不一致(并非所有作业都写入,部分写入等)
  2. 始终传递2个工件report1.txt,report2.txt,因此chrome的作业仅在#1中写入,Safari的作业在#2中写入
    • 根本不工作,上帝知道原因
  3. 具有2个工件的依赖项report1.txt,report2.txt
    • 由于某些原因,在安装阶段生成的工件node_modules不会传递到下一个阶段。

我不再有用于此设置的示例,它们很杂乱,但是我为您提供了.gitlab-ci.yml的示例,也许您可​​以帮助我。

<?xml version="1.0" encoding="utf-8"?><!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="8 -9 640.6 640.6" enable-background="new 8 -9 640.6 640.6" xml:space="preserve">
    <g id="chica">
        <g id="peinados">
            <g id="pelo15">
                <g id="colorpelo_55_">
                    <path fill="#895C38" d="M258.6,245.7c-..."/>
                </g>
            </g>
        </g>
    </g>
</svg>

1 个答案:

答案 0 :(得分:1)

您发布的文件中至少存在几个可能的问题:

  1. artifacts.name未定义,因此将使用默认的“工件”字符串。当多个作业在同一主机上并行运行时,存在构成一个工件文件被另一个工件文件覆盖的风险。 定义自定义artifacts:name来解决覆盖问题。

  2. 如果将report.txt存储在同一文件夹中,请在完成作业之前重命名它,这样报告文件将不会在您的report阶段作业中被覆盖,在该阶段所有请求的工件存档将被解压缩到相同的位置。

  3. 似乎没有一项工作(启动,质量,语言)导出report.txt文件。添加report.txtscreenshots文件夹以导出它。

  4. 截屏(和报告)仅在作业失败时导出。如果不是想要的行为,请将artifacts:when更改为on_successalways

  5. 如果其中一个测试作业失败,则整个管道将失败。如果该管道仅用于测试和导出结果,则应允许测试作业失败,而不会导致整个管道失败,allow_failure

一切总结上面写的,这里的提出改变了YML文件:

stages:
  - install
  - test
  - report

#
# Templates
#

# Tags can't be defined on a global scope for now
# Ref: https://gitlab.com/gitlab-org/gitlab-ce/issues/23434
.default: &default
  tags: ['macbook']

.node_modules:
  artifacts: &node_modules
    paths: ['node_modules']
    when: always

.test_reports:
  artifacts: &test_reports
    paths:
      - screenshot
      - reports
    when: always

.chrome_template: &chrome_template
  environment:
    name: chrome
  variables: &chrome_template_var
    SELENIUM_BROWSER: chrome

.safari_template: &safari_template
  environment:
    name: safari
  variables: &safari_template_var
    SELENIUM_BROWSER: safari

#
# Jobs
#

# Install

install:
  <<: *default
  stage: install
  except: ['tags']
  script:
    - npm install
  artifacts: *node_modules

# Test

.test: &test
  <<: *default
  stage: test
  script:
    - npm run test
    # Move report to individual file to fix overwriting it by other artifacts
    - mkdir -p reports
    - mv report.txt reports/report_${CI_JOB_NAME}.txt
  retry: 1
  artifacts: *test_reports
  # Allow tests to fail, exporting artifacts to the final stage
  allow_failure: true

.test_startup: &test_startup
  <<: *test
  variables: &startup_var
    SPEC: startup

.test_quality: &test_quality
  <<: *test
  variables: &quality_var
    SPEC: quality

.test_language: &test_language
  <<: *test
  variables: &language_var
    SPEC: language


test:startup:chrome:
  <<: *test_startup
  <<: *chrome_template
  variables:
    <<: *startup_var
    <<: *chrome_template_var

test:language:chrome:
  <<: *test_language
  <<: *chrome_template
  variables:
    <<: *language_var
    <<: *chrome_template_var

test:quality:chrome:
  <<: *test_quality
  <<: *chrome_template
  variables:
    <<: *quality_var
    <<: *chrome_template_var

test:startup:safari:
  <<: *test_startup
  <<: *safari_template
  variables:
    <<: *startup_var
    <<: *safari_template_var

test:language:safari:
  <<: *test_language
  <<: *safari_template
  variables:
    <<: *language_var
    <<: *safari_template_var

test:quality:safari:
  <<: *test_quality
  <<: *safari_template
  variables:
    <<: *quality_var
    <<: *safari_template_var

# Report

report:
  <<: *default
  stage: report
  script:
    # Summarize reports before exporting
    # Ignore errors when there are no reports to export
    - cat reports/*.txt > report.txt | true
  artifacts:
    paths:
      - screenshot
      - report.txt

请检查多个失败的测试作业是否不会覆盖“截屏”文件夹的内容。否则,您需要以与“ report.txt”文件相同的方式移动屏幕截图。

相关问题