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