how to run nose2 tests in Jenkins build python

428 Views Asked by At

I am running a Jenkins pipeline where I have a flask app to run and then test (using nose)

the current Jenkinsfile I am using is

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 creates the docker image and download the pythnon requirements. I get and error when running nose2 from shell script

with this error

+ 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

what am I missing?

1

There are 1 best solutions below

0
On

I fixed it (i.e. the jenkins build works) by changing the Jenkinfile in this way

    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
    '''

I would have preferred to run nose2 like I do on my machine. if anyone knows out to fix this would be great