Skip to content

Commit b2c0801

Browse files
committed
Add a helper for ImageJ's Jenkins jobs
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 749bddc commit b2c0801

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

git-info-for-jenkins-job.groovy

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/jenkins-cli
2+
3+
/**
4+
* Prints author information for use by Git about the user who started a given
5+
* Jenkins build. Example usage in an 'Execute shell' build step:
6+
*
7+
* eval "$(jenkins-cli groovy git-info-for-job.groovy $JOB_NAME $BUILD_NUMBER)"
8+
*/
9+
10+
if (this.args.length != 2) {
11+
throw new IllegalArgumentException("Usage: author-ident <job> <build-number>")
12+
}
13+
14+
projectName = this.args[0]
15+
buildNumber = Integer.parseInt(this.args[1])
16+
17+
map = jenkins.model.Jenkins.instance.getItemMap()
18+
project = map.get(projectName)
19+
build = project.getBuildByNumber(buildNumber)
20+
21+
emailMap = [
22+
"Curtis Rueden": "[email protected]",
23+
"Johannes Schindelin": "[email protected]",
24+
"Mark Hiner": "[email protected]"
25+
]
26+
27+
for (cause in build.getCauses()) try {
28+
name = cause.getUserName()
29+
println('GIT_AUTHOR_NAME="' + name + '"')
30+
println('export GIT_AUTHOR_NAME')
31+
email = emailMap[name]
32+
if (email == null) {
33+
email = name.toLowerCase().replaceAll(' ', '.') + '@jenkins.imagej.net'
34+
}
35+
println('GIT_AUTHOR_EMAIL="' + email + '"')
36+
println('export GIT_AUTHOR_EMAIL')
37+
break
38+
} catch (e) { /* ignore */ }

0 commit comments

Comments
 (0)