【问题标题】:Bitbucket / I cannot see the artifacts in pipelinesBitbucket / 我看不到管道中的工件
【发布时间】:2018-11-19 12:01:02
【问题描述】:

我在 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

也许我输入了错误的路径,但我不确定。

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

【问题讨论】:

    标签: continuous-integration bitbucket-pipelines artifact


    【解决方案1】:

    我认为它没有记录在任何地方,但artifacts 只接受来自$BITBUCKET_CLONE_DIR 的相对目录。当我运行我的管道时,它说:Cloning into '/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 前缀(有关此解决方案的更多详细信息,请在此处查看此答案:https://community.atlassian.com/t5/Bitbucket-questions/Pipeline-script-continue-even-if-a-script-fails/qaq-p/79469)。这将防止管道停止,但也确保您的管道始终完成!这当然不是你想要的。因此,我建议您单独运行 cypress 测试并在管道中创建第二步以检查 cypress 的输出。像这样的:

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

    # bitbucket-pipelines.yml
    
    image: cypress/base:10
    options: max-time: 20
    pipelines: 
      default: 
        - step:
            name: Run tests
            script:
                - npm install
                - npm run test
                - set +e npm run testcypress
            artifacts: 
                - cypress/screenshots/*.png
        -step:
            name: Evaluate Cypress
            script:
                - chmod +x check_cypress_output.sh
                - ./check_cypress_output.sh
    

    # 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
    

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

    【讨论】:

    • 您好 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 错误! errno 3 npm 错误! @test:'cypress run' npm ERR!退出状态 3 npm ERR! npm 错误! @test 脚本失败。 npm 错误!这可能不是 npm 的问题。上面可能有额外的日志输出。 npm 错误!可以在以下位置找到此运行的完整日志:npm ERR! /root/.npm/_logs/2018-12-05T11_19_56_845Z-debug.log 我想看到的是测试出现问题时的截图(当时)
    • 对该评论的回复太长,所以我更新了我的答案;)
    【解决方案2】:

    由于videosscreenshots 中的附加文件夹,递归搜索 (/**) 对我有用 Cypress 3.1.0

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

    【讨论】:

      【解决方案3】:

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

      "cypress:pipeline": "cypress run --env user=${E2E_USER_EMAIL},pass=${E2E_USER_PASSWORD} --browser chrome --spec cypress/integration/src/**/*.spec.ts"

      pipelines:
        custom:
          healthCheck:
            - step:
                name: Integration and E2E Test
                script:
                  - npm install
                  - npm run cypress:pipeline
                artifacts:
                  # store any generated images as artifacts
                  - cypress/screenshots/**/*.png
      

      【讨论】:

        猜你喜欢
        • 2019-03-03
        • 1970-01-01
        • 2020-07-22
        • 1970-01-01
        • 2023-03-29
        • 2020-07-31
        • 1970-01-01
        • 1970-01-01
        • 2021-06-16
        相关资源
        最近更新 更多