• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gitlab CI/CD pipeline cannot run php spark

#1
i'm implementing gitlab CI/CD pipeline in my CI4 project.

running 
PHP Code:
php spark migrate 

 in gitlab CI/CD script get this error

Code:
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-08-11 16:49:30pm

ERROR: 404
Can't find a route for 'cimigrate'.

ERROR: Job failed: exit status 1

I don't get error when execute migration on live server.

is it bug? please help...
thanks.
Reply

#2
Found the problem in CodeIgniter.php file, detectEnvironment() function.

PHP Code:
protected function detectEnvironment()
{
    
// Make sure ENVIRONMENT isn't already set by other means.
    
if (! defined('ENVIRONMENT'))
    {
        
// running under Continuous Integration server?
        
if (getenv('CI') !== false)
        {
            
define('ENVIRONMENT''testing');
        }
        else
        {
            
define('ENVIRONMENT'$_SERVER['CI_ENVIRONMENT'] ?? 'production');
        }
    }


When we run under CI server, we will always get ENVIRONMENT = testing.

Testing environment can't get clirequest in getRequestObject() function if we run it in cli.

PHP Code:
protected function getRequestObject()
{
    if (
$this->request instanceof Request)
    {
        return;
    }

    if (
is_cli() && ENVIRONMENT !== 'testing')
    {
        
// @codeCoverageIgnoreStart
        
$this->request Services::clirequest($this->config);
        
// @codeCoverageIgnoreEnd
    
}
    else
    {
        
$this->request Services::request($this->config);
        
// guess at protocol if needed
        
$this->request->setProtocolVersion($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1');
    }


It means we dont have flexibility to change/use custom ENVIRONMENT in CI/CD server.

Can i request to remove the code that always set ENVIRONMENT = testing in CI/CD server?
or
request to allow testing environment to get/use clirequest?
Reply

#3
You can set the environment in the env file.

Code:
#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------

# CI_ENVIRONMENT = production
CI_ENVIRONMENT = developement
# CI_ENVIRONMENT = testing

You can also set it in the root .htaccess file.

Code:
#SetEnv CI_ENVIRONMENT 'production'
SetEnv CI_ENVIRONMENT 'development'
#SetEnv CI_ENVIRONMENT 'testing'

Worse case add the environment to the spark file.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#4
My work around right now is by ignoring environment (start with an empty environment)

PHP Code:
env -i php spark migrate -n App 

I'm still digging to find a better way

(08-12-2020, 05:03 AM)InsiteFX Wrote: You can set the environment in the env file.

Code:
#--------------------------------------------------------------------
# ENVIRONMENT
#--------------------------------------------------------------------

# CI_ENVIRONMENT = production
CI_ENVIRONMENT = developement
# CI_ENVIRONMENT = testing

You can also set it in the root .htaccess file.

Code:
#SetEnv CI_ENVIRONMENT 'production'
SetEnv CI_ENVIRONMENT 'development'
#SetEnv CI_ENVIRONMENT 'testing'

Worse case add the environment to the spark file.

Changing environment in .env file doesnt work for me. I'll try the .htaccess approach
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.