Files
toolbox/app/Console/Commands/JenkinsMonitorCommand.php

42 lines
1.2 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Services\JenkinsMonitorService;
use Illuminate\Console\Command;
class JenkinsMonitorCommand extends Command
{
protected $signature = 'jenkins:monitor';
protected $description = '轮询 Jenkins 检查新构建并发送钉钉通知';
public function handle(JenkinsMonitorService $service): void
{
$this->info('开始检查 Jenkins 构建...');
$results = $service->checkAllProjects();
if (isset($results['skipped'])) {
$this->warn('跳过检查: ' . ($results['reason'] ?? 'unknown'));
return;
}
foreach ($results as $slug => $result) {
if (isset($result['skipped'])) {
$this->line(sprintf('[%s] 跳过: %s', $slug, $result['reason'] ?? 'unknown'));
continue;
}
$newBuilds = $result['new_builds'] ?? [];
if (empty($newBuilds)) {
$this->line(sprintf('[%s] 无新构建', $slug));
} else {
$this->info(sprintf('[%s] 发现 %d 个新构建: #%s', $slug, count($newBuilds), implode(', #', $newBuilds)));
}
}
$this->info('检查完成');
}
}