This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Jenkinsのビルド中のジョブを取得する | |
def jobs = hudson.model.Hudson.instance.items.findAll { it.isBuilding() } | |
jobs.each { println it.name } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 1. depjobnameで指定したジョブよりも自分自身が先にキューに入った場合は、自分自身のビルドを即実行する。 | |
// 2. depjobnameで指定したジョブよりも自分自身が後にキューに入った場合は、depjobnameの終了を待つ。 | |
// 2-1. ポーリング方式で終了を待つ | |
// 2-2. 最大リトライ回数は retrycount で指定 | |
// 2-3. リトライ間隔は sleeptime で指定(単位はミリ秒) | |
// 3. depjobnameで指定したジョブが存在しなかった場合は、ビルドを失敗させるためにあえて例外が発生する | |
// ようにしています。 | |
// 4. 設定手順 | |
// 4-1. Groovy Pluginをインストールする |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// プラクティスとして良いかどうかは別として、他のプロジェクト固有の環境変数を得る方法 | |
// 以下は groovy plugin の Execute system Groovy script の中で使用して | |
// TEST プロジェクトの WORKSPACE 環境変数の情報を得る例 | |
def jobname = "TEST" | |
def envname = "WORKSPACE" | |
def job = hudson.model.Hudson.instance.getItem(jobname) | |
def envVars= job.lastBuild.properties.get("envVars") | |
println envVars[envname] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 他のプロジェクトのビルドを実行する方法 | |
// 以下は groovy plugin の Execute system Groovy script の中で使用して | |
// TEST プロジェクトのビルドを実行する例 | |
def jobname = "TEST" | |
hudson.model.Hudson.instance.getItem(jobname).scheduleBuild() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 他のプロジェクトのビルドを中止する方法 | |
// 以下は groovy plugin の Execute system Groovy script の中で使用して | |
// TEST プロジェクトのビルドを中止する例 | |
def jobname = "TEST" | |
def job = hudson.model.Hudson.instance.getItem(jobname) | |
assert job, "ERROR: Can't find the job $jobname." | |
def lastbuild = job.lastBuild | |
if( lastbuild ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// あるプロジェクトの下流ビルドと上流ビルドを取得する方法 | |
// 以下は groovy plugin の Execute system Groovy script の中で使用して | |
// TEST プロジェクトの下流ビルドと上流ビルドを取得する例 | |
def jobname = "TEST" | |
def job = hudson.model.Hudson.instance.getItem(jobname) | |
def dep = hudson.model.Hudson.instance.dependencyGraph | |
assert job, "ERROR: Can't find the job $jobname." | |
assert dep, "ERROR: Can't get the dependency graph." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 動作中のプロジェクト自身を取得する方法 | |
// 以下は groovy plugin の Execute system Groovy script の中で使用して | |
// groovy plugin自体を実行しているプロジェクトを取得する例 | |
def currentJob = Thread.currentThread().executable.project | |
println currentJob.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 他プロジェクトの指定期間内の成功ビルドの成果物ディレクトリを一覧する方法 | |
// 以下は groovy plugin の Execute system Groovy script の中で使用して | |
// TESTプロジェクトの | |
// 2011/3/1 00:00:00 から | |
// TESTプロジェクトの最終ビルド まで | |
// の期間を対象にして成功ビルドの成果物ディレクトリを一覧する | |
def jobname = "TEST" | |
def job = hudson.model.Hudson.instance.getItem(jobname) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by IntelliJ IDEA. | |
* User: kyon | |
* Date: 11/03/15 | |
* Time: 0:54 | |
* To change this template use File | Settings | File Templates. | |
*/ | |
String.metaClass.toXML = { builder, entry -> | |
builder."${entry.key}"(entry.value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// new Random と nextIntを使用 | |
[*0..9,*'a'..'z',*'A'..'Z','_'].with{a->println new Random().with{(1..16).collect{a[nextInt(a.size())]}.join()}} | |
// Math.randomを使用 | |
[*0..9,*'a'..'z',*'A'..'Z','_'].with{a->println((1..16).collect{a[(int)Math.random()*a.size()]}.join())} | |
// def と println版 | |
def a=[*0..9,*'a'..'z',*'A'..'Z','_'];println((1..16).collect{a[(int)Math.random()*a.size()]}.join()) |
OlderNewer