#feature: add Jenkins deploy monitor & log clean task
This commit is contained in:
41
app/Console/Commands/JenkinsMonitorCommand.php
Normal file
41
app/Console/Commands/JenkinsMonitorCommand.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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('检查完成');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user