gpt4 book ai didi

python - 如何在Jenkins构建python中运行nose2测试

转载 作者:太空宇宙 更新时间:2023-11-03 19:57:53 40 4
gpt4 key购买 nike

我正在运行一个 Jenkins 管道,其中有一个 Flask 应用程序可以运行,然后进行测试(使用 Nose )

我当前使用的 Jenkinsfile 是

pipeline {
agent { docker { image 'python:3.8.0' } }
stages {
stage('build') {
steps {
withEnv(["HOME=${env.WORKSPACE}"]) {
sh 'python --version'
sh 'python -m pip install --upgrade pip'
sh 'pip install --user -r requirements.txt'

sh script:'''
#!/bin/bash
echo "This is start $(pwd)"
cd ./flask/section5
echo "This is $(pwd)"
python create_table.py
python myapp.py &
nose2
'''
}
}
}
}
}

Jenkins 创建 docker 镜像并下载 pythnon 要求。从shell脚本运行nose2时出现错误

出现此错误

+ pwd
+ echo This is start .jenkins/workspace/myflaskapptest_master
This is start .jenkins/workspace/myflaskapptest_master
+ cd ./flask/section5
+ pwd
+ echo This is .jenkins/workspace/myflaskapptest_master/flask/section5
This is .jenkins/workspace/myflaskapptest_master/flask/section5
+ python create_table.py
DONE
+ nose2+
python myapp.py
.jenkins/workspace/myflaskapptest_master@tmp/durable-1518e85e/script.sh: 8: .jenkins/workspace/myflaskapptest_master@tmp/durable-1518e85e/script.sh: nose2: not found

我错过了什么?

最佳答案

我通过以这种方式更改 Jenkinfile 修复了它(即 jenkins 构建工作)

    sh script:'''
#!/bin/bash
echo "This is start $(pwd)"
cd ./flask/section5
echo "This is $(pwd)"
python create_table.py
python myapp.py &
cd ./tests
python test.py
'''

我更愿意像在我的机器上那样运行nose2。如果有人知道解决这个问题那就太好了

关于python - 如何在Jenkins构建python中运行nose2测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59446380/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com