首页 > 解决方案 > 如何在Jenkins构建python中运行nose2测试

问题描述

我正在运行一个 Jenkins 管道,我有一个烧瓶应用程序要运行然后测试(使用鼻子)

我正在使用的当前 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

我错过了什么?

标签: pythondockerunit-testingjenkinsnose2

解决方案


我通过以这种方式更改 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。如果有人知道解决这个问题会很棒


推荐阅读