File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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" : " ctrueden@wisc.edu" ,
23+ " Johannes Schindelin" : " johannes.schindelin@gmx.de" ,
24+ " Mark Hiner" : " hinerm@gmail.com"
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 */ }
You can’t perform that action at this time.
0 commit comments