Continuous integration Bitbucket/I无法看到管道中的工件

Continuous integration Bitbucket/I无法看到管道中的工件,continuous-integration,bitbucket-pipelines,artifact,Continuous Integration,Bitbucket Pipelines,Artifact,我在CI环境上运行e2e测试,但在管道中看不到工件 bitbucket-pipelines.yml: image: cypress/base:10 options: max-time: 20 pipelines: default: -step: script: - npm install -npm run test artifacts: -/opt/atlassia

我在CI环境上运行e2e测试,但在管道中看不到工件

bitbucket-pipelines.yml:

image: cypress/base:10
options: max-time: 20
pipelines: 
  default: 
    -step: 
        script: 
            - npm install 
            -npm run test 
        artifacts: 
            -/opt/atlassian/pipelines/agent/build/cypress/screenshots/* 
            -screenshots/*.png

也许我打错了路径,但我不确定


有人知道我做错了什么吗?

我不认为它在任何地方都有文档记录,但
artifacts
只接受来自
$BITBUCKET\u CLONE\u DIR
的相对目录。当我运行管道时,它会说:
克隆到“/opt/atlassian/pipelines/agent/build”…
,所以我认为工件是相对于该路径的。我的猜测是,如果您将其更改为类似的内容,它将起作用:

image: cypress/base:10
options: max-time: 20
pipelines: 
  default: 
    -step: 
        script: 
            - npm install 
            -npm run test 
        artifacts: 
            - cypress/screenshots/*.png

编辑

从您的评论中,我现在明白了真正的问题是什么:BitBucket管道被配置为在任何非零退出代码处停止。这意味着当cypress测试失败时,管道执行将停止。因为工件是在管道的最后一步之后存储的,所以不会有任何工件

要解决此问题,必须确保在保存图像之前管道不会停止。一种方法是在
npm run test
部分前面加上
set+e
(有关此解决方案的更多详细信息,请查看以下答案:)。这将防止管道停止,但也确保管道始终完成!这当然不是你想要的。因此,我建议您单独运行cypress测试,并在管道中创建第二步来检查cypress的输出。大概是这样的:

# package.json

...
"scripts": {
  "test": "<your test command>",
  "testcypress": "cypress run ..."
...

此脚本将检查cypress是否创建了任何工件,如果创建了工件,则管道将失败。我不确定这是否正是您所需要的,但这可能是朝着这个方向迈出的一步。

递归搜索(
/**
)在Cypress 3.1.0中对我起到了作用,因为
视频
屏幕截图

# [...]
pipelines: 
  default: 
    - step:
      name: Run tests
      # [...]
      artifacts:
        - cypress/videos/** # Double star provides recursive search.
        - cypress/screenshots/** 

这是我的工作方案 “cypress:pipeline”是我的bitbucket配置文件中用于运行cypress的自定义管道。 请在工件部分尝试cypress/screenshots/***.png

“cypress:pipeline”:“cypress运行--env user=${E2E_user_EMAIL},pass=${E2E_user_PASSWORD}--浏览器chrome--spec-cypress/integration/src//*.spec.ts” 管道: 自定义: 健康检查: -步骤: 名称:集成与E2E测试 脚本: -npm安装 -npm运行cypress:管道 人工产品: #将任何生成的图像存储为工件
-cypress/screenshots/
/*.png

你好,Gijs Wobben,谢谢你的留言。不幸的是,它仍然不起作用。我已经尝试了很多不同的方法来解决它,但我不知道为什么它不起作用我不确定你是否已经这样做了,但是您可能会尝试在管道定义中添加一些ls命令,以查看容器中发生了什么:-ls-la/opt/atlassian/pipelines/agent/build-ls-la/opt/atlassian/pipelines/agent/build/cypress-ls-la/opt/atlassian/pipelines/agent/build/cypress/screenshots…我尝试了这个,但仍然没有发生任何事情。我(在每次失败的管道测试中)得到的是:npm ERR!代码ELIFECYCLE npm ERR!错误3 npm错误@测试:“cypress run”npm错误!退出状态3 npm错误!npm错误!在@test脚本中失败。npm错误!这可能不是npm的问题。上面可能还有其他日志输出。npm错误!此运行的完整日志可在以下位置找到:npm ERR/root/.npm/_logs/2018-12-05T11_19_56_845Z-debug.log我想看到的是测试出错时的屏幕截图(当时)对此评论的响应太长,所以我更新了答案;)
# check_cypress_output.sh

# Check if the directory exists
if [ -d "./usertest" ]; then

    # If it does, check if it's empty
    if [ -z "$(ls -A ./usertest)" ]; then

        # Return the "all good" signal to BitBucket if the directory is empty
        exit 0
    else

        # Return a fault code to BitBucket if there are any images in the directory
        exit 1
    fi

# Return the "all good" signal to BitBucket
else
    exit 0
fi
# [...]
pipelines: 
  default: 
    - step:
      name: Run tests
      # [...]
      artifacts:
        - cypress/videos/** # Double star provides recursive search.
        - cypress/screenshots/**