facebook twitter hatena line email

「Jenkins/crontab形式に変更するスクリプト」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「<pre> <?php exec("ls jobs/config.xml | xargs grep '<command>'", $res_commands, $return_var); exec("ls jobs/: config.xml | xargs grep '<spec>'", $res_specs, $return_var)...」)
 
(コマンドのipの一括置換)
 
(同じ利用者による、間の5版が非表示)
行1: 行1:
 +
jenkinsに登録したスケジュール(spec)とシェルスクリプト(command)をcrontabな表示に変更する
 +
 +
$ vi /var/lib/jenkins/crontab.php
 +
 
<pre>
 
<pre>
 
<?php
 
<?php
行17: 行21:
 
         }
 
         }
 
}
 
}
foreach ($res_numToKeeps as $key => $numToKeep) {
+
// foreach ($res_numToKeeps as $key => $numToKeep) {
         list($hash, $dummy) = explode("/config.xml", $numToKeep);
+
//         list($hash, $dummy) = explode("/config.xml", $numToKeep);
         if (preg_match('!<numToKeep>(.+)</numToKeep>!', $numToKeep, $matches)) {
+
//         if (preg_match('!<numToKeep>(.+)</numToKeep>!', $numToKeep, $matches)) {
                 $crons[$hash]['numToKeep'] = $matches[1];
+
//                 $crons[$hash]['numToKeep'] = $matches[1];
         }
+
//         }
}
+
// }
 
ksort($crons);
 
ksort($crons);
 
print nl2br(print_r($crons,1));
 
print nl2br(print_r($crons,1));
行29: 行33:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
==確認コマンド==
 +
grep "<command>" /var/lib/jenkins/jobs/*/config.xml
 +
 +
==コマンドのipの一括置換==
 +
sudo grep "<command>" /var/lib/jenkins/jobs/*/config.xml -l | sudo xargs sed -i.bak -e "s/158.199.xxx.xxx/158.199.yyy.yyy/g"

2017年3月13日 (月) 22:05時点における最新版

jenkinsに登録したスケジュール(spec)とシェルスクリプト(command)をcrontabな表示に変更する

$ vi /var/lib/jenkins/crontab.php

<?php
exec("ls jobs/*/config.xml | xargs grep '<command>'", $res_commands, $return_var);
exec("ls jobs/*/config.xml | xargs grep '<spec>'", $res_specs, $return_var);
exec("ls jobs/*/config.xml | xargs grep '<numToKeep>'", $res_numToKeeps, $return_var);
$crons = array();
foreach ($res_commands as $key => $command) {
        list($hash, $dummy) = explode("/config.xml", $command);
        if (preg_match('!<command>(.+)</command>!', $command, $matches)) {
                $crons[$hash]['command'] = $matches[1];
        }
}
foreach ($res_specs as $key => $spec) {
        list($hash, $dummy) = explode("/config.xml", $spec);
        if (preg_match('!<spec>(.+)</spec>!', $spec, $matches)) {
                $crons[$hash]['spec'] = $matches[1];
        }
}
// foreach ($res_numToKeeps as $key => $numToKeep) {
//         list($hash, $dummy) = explode("/config.xml", $numToKeep);
//         if (preg_match('!<numToKeep>(.+)</numToKeep>!', $numToKeep, $matches)) {
//                 $crons[$hash]['numToKeep'] = $matches[1];
//         }
// }
ksort($crons);
print nl2br(print_r($crons,1));
foreach ($crons as $cron) {
        echo sprintf("%s %s\n", $cron['spec'], $cron['command']);
}

確認コマンド

grep "<command>" /var/lib/jenkins/jobs/*/config.xml

コマンドのipの一括置換

sudo grep "<command>" /var/lib/jenkins/jobs/*/config.xml -l | sudo xargs sed -i.bak -e "s/158.199.xxx.xxx/158.199.yyy.yyy/g"