简体   繁体   中英

Uncaught ReflectionException: Class request does not exist in Jenkins

I have jenkins up and running on a laravel project. It was working normally till some days ago, then some weird error started to pop up.

PHP Fatal error:  Uncaught ReflectionException: Class request does not exist in /var/lib/jenkins/workspace/Test_fix_changing-jenkinsfile/vendor/laravel/framework/src/Illuminate/Container/Container.php:809

I did some digging on the inte.net, i have cleaned and chmod 777 into my bootstrap/cache folder also checked my CreatesApplication.php to make sure i'm importing Kernel from the right place use Illuminate\Contracts\Console\Kernel; everyting seams normal to me. This error show regardless if all tests passes or fail and this is only happening inside jenkins.

I'm using Laravel version 7.30 here's my jenkis file.

pipeline {
  agent any
    environment {
    GIT_COMMIT_SHORT = "a${env.GIT_COMMIT.take(7)}"
    DB_DATABASE_AUX = "a${env.GIT_COMMIT.take(7)}"
  }
  stages {
    stage("Build") {
      steps {
        sh 'cp ../.env .'
        sh 'php --version'
        sh 'composer install'
        sh 'composer --version'
        sh 'composer dump-autoload'
        sh 'php artisan key:generate'
      }
    }
    stage('Test backend') {
      steps {
          sh '/usr/bin/php artisan mysql:createdb $GIT_COMMIT_SHORT'
          sh '/usr/bin/php artisan clear-compiled'
          sh '/usr/bin/php artisan optimize'
          sh '/usr/bin/php artisan route:clear'
          sh '/usr/bin/php artisan view:clear'
          sh '/usr/bin/php artisan cache:clear'
          sh 'echo ""DB_DATABASE=${DB_DATABASE_AUX}>> .env'
          sh 'chmod 777 bootstrap/cache'
          sh '/usr/bin/php artisan config:cache'
          sh '/usr/bin/php artisan config:clear'
          sh '/usr/bin/php artisan optimize:clear'
          sh '/usr/bin/php artisan migrate:fresh'
          sh '/usr/bin/php artisan passport:install'
          sh '/usr/bin/php vendor/bin/phpunit tests/Unit/ --stop-on-failure'
          sh '/usr/bin/php vendor/bin/phpunit tests/Feature/ --stop-on-failure'
      }
      post {
        always {
          sh '/usr/bin/php artisan mysql:deletedb $GIT_COMMIT_SHORT'
        }
      }
    }
  }
}

Any idea on how to deal with it would be welcome.

That error suggests that you're trying to access the request before it's been bound to the service container. This would happen if you're using the request() helper or Request facade before a request has been passed to the Http Kernel.

Is it possible that you added new code that may be trying to access the request in your tests before you've run $this->get() or any other HTTP helper method?

In Laravel 7, this is where "request" is bound to the container and this is where the container is failing (based on your error message). This means that the container is trying to resolve request as a class instead of use an instance that's already been bound to that name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM