Bitbucket /我看不到管道中的文物

问题描述 投票:0回答:1

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

enter image description here

enter image description here

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

有没有人有任何想法我做错了什么?

continuous-integration bitbucket-pipelines artifact
1个回答
0
投票

我不认为它记录在任何地方,但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是否创建了任何工件,如果确实如此,将会使管道失败。我不确定这正是你需要的,但它可能是朝这个方向迈出的一步。


0
投票

由于/**videos中的附加文件夹,递归搜索(screenshots)为我的赛普拉斯3.1.0工作

# [...]
pipelines: 
  default: 
    - step:
      name: Run tests
      # [...]
      artifacts:
        - cypress/videos/** # Double star provides recursive search.
        - cypress/screenshots/** 
© www.soinside.com 2019 - 2024. All rights reserved.