This file contains 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 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 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 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 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 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 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 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()) |
This file contains 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
// st = [時,分] が [0,0]~[24,0]の範囲内かどうかをチェック | |
def isValidTime = { st -> ((0..23).contains(st[0]) && (0..59).contains(st[1])) || (st[0] == 24 && st[1] == 0) } | |
// st1 = [時,分], st2 = [時,分] が st1 <= st2 を満たすかどうかをチェック | |
def isNotGreaterThan = { st1, st2 -> st1[0] < st2[0] ? true : (st1[0] == st2[0] ? st1[1] <= st2[1] : false) } | |
// pt = [開始時,開始分,終了時,終了分] が [開始時,開始分] <= [終了時,終了分] を満たすかどうかをチェック | |
def isValidPair = { pt -> isValidTime(pt[0,1]) && isValidTime(pt[2,3]) && isNotGreaterThan(pt[0,1],pt[2,3]) } | |
// pt1 = [開始時,開始分,終了時,終了分], pt2 = [開始時,開始分,終了時,終了分] がオーバーラップしているかどうかをチェック |
This file contains 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
class MyTime implements Comparable { | |
int hour | |
int minutes | |
MyTime(hour, minutes) { | |
this.hour = hour | |
this.minutes = minutes | |
assert isValid(), "The time ${this} is not valid." | |
} | |
int compareTo(that) { | |
(hour*60+minutes) <=> (that.hour*60+that.minutes) |
OlderNewer