enj*_*yit 9 continuous-integration artifact bitbucket-pipelines
我在 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
Run Code Online (Sandbox Code Playgroud)
也许我输入了错误的路径,但我不确定。
有人知道我做错了什么吗?
我认为它没有记录在任何地方,但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
Run Code Online (Sandbox Code Playgroud)
编辑
从您的评论中,我现在明白真正的问题是什么: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 ..."
...
Run Code Online (Sandbox Code Playgroud)
# 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
Run Code Online (Sandbox Code Playgroud)
# 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
Run Code Online (Sandbox Code Playgroud)
该脚本将检查 cypress 是否创建了任何工件,如果创建了,将使管道失败。我不确定这是否正是您所需要的,但这可能是朝着这个方向迈出的一步。
| 归档时间: |
|
| 查看次数: |
10974 次 |
| 最近记录: |