Migrating to Jenkins

Edit on GitHub

This document describes how to migrate to the Jenkins scheduler and set up jobs.

Jenkins is the default scheduler shipped with Spryker Demo Shops. Follow the instructions in the document only if you previously migrated to another scheduler.

Prerequisites

Check composer.json and package.json to make sure that the following Composer packages are installed:

  • spryker/scheduler: *
  • spryker/scheduler-extension: *
  • spryker/scheduler-jenkins: *

1. Configure Jenkins

  1. In src/Pyz/Shared/Scheduler/SchedulerConfig.php, add the scheduler name constant:
class SchedulerConfig extends AbstractSharedConfig
{
    public const SCHEDULER_JENKINS = 'jenkins';
}
  1. In src/Pyz/Zed/Console/ConsoleDependencyProvider.php, add the console commands:
/**
 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
 * @method \Pyz\Zed\Console\ConsoleConfig getConfig()
 */
class ConsoleDependencyProvider extends SprykerConsoleDependencyProvider
{
    ...
    /**
     * @param \Spryker\Zed\Kernel\Container $container
     *
     * @return \Symfony\Component\Console\Command\Command[]
     */
    protected function getConsoleCommands(Container $container): array
    {
        $commands = [
          ...
          new SchedulerSetupConsole(),
          new SchedulerCleanConsole(),
          new SchedulerSuspendConsole(),
          new SchedulerResumeConsole(),
          ...
        ];
        ...
    }
    ...
}
  1. In src/Pyz/Zed/Scheduler/SchedulerDependencyProvider.php, add the adapter:
class SchedulerDependencyProvider extends SprykerSchedulerDependencyProvider
{
    ...
    /**
     * @return \Spryker\Zed\SchedulerExtension\Dependency\Plugin\ScheduleReaderPluginInterface[]
     */
    protected function getSchedulerReaderPlugins(): array
    {
        return [
            new PhpScheduleReaderPlugin(),
        ];
    }
    /**
     * @return \Spryker\Zed\SchedulerExtension\Dependency\Plugin\SchedulerAdapterPluginInterface[]
     */
    protected function getSchedulerAdapterPlugins(): array
    {
            ...
            SchedulerConfig::SCHEDULER_JENKINS => new SchedulerJenkinsAdapterPlugin(),
        ];
    }
}

2. Configure the project

  1. To be able to use enabled schedulers from environment variables, adjust the project configuration with SchedulerConstants::ENABLED_SCHEDULERS:
$config[SchedulerConstants::ENABLED_SCHEDULERS] = [
    SchedulerConfig::SCHEDULER_JENKINS,
];
  1. Init configuration for each Jenkins:
$config[SchedulerJenkinsConstants::JENKINS_CONFIGURATION] = [
    SchedulerConfig::SCHEDULER_JENKINS => [
        SchedulerJenkinsConfig::SCHEDULER_JENKINS_BASE_URL => sprintf(
            '%s://%s:%s/',
            getenv('SPRYKER_SCHEDULER_PROTOCOL') ?: 'http',
            getenv('SPRYKER_SCHEDULER_HOST'),
            getenv('SPRYKER_SCHEDULER_PORT')
        ),
    ],
];

$config[SchedulerJenkinsConstants::JENKINS_TEMPLATE_PATH] = getenv('SPRYKER_JENKINS_TEMPLATE_PATH') ?: null;

3. Configure Jenkins jobs

Create or update the Jenkins job list in config/Zed/cronjobs/jenkins.php. To learn how to add jobs, see Adding and configuring cronjobs.