-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.xml
107 lines (97 loc) · 4.33 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<project name="jenkins-bugs-master-branch" default="sync" basedir=".">
<property environment="env"/>
<condition property="changeLogCount" value="${env.CHANGESET_SIZE}" else="1">
<isset property="env.CHANGESET_SIZE"/>
</condition>
<target name="is-first-build">
<condition property="first.build">
<equals arg1="${env.BUILD_NUMBER}" arg2="1"/>
</condition>
</target>
<!-- Check environment variables only in builds 2+ -->
<target name="check-non-initial-build" description="Check git env vars at build 2+" depends="is-first-build" if="env.JENKINS_URL" unless="first.build">
<echo>GIT_PREVIOUS_COMMIT is ${env.GIT_PREVIOUS_COMMIT}</echo>
<echo>env.GIT_PREVIOUS_SUCCESSFUL_COMMIT is ${env.GIT_PREVIOUS_SUCCESSFUL_COMMIT}</echo>
<fail message="GIT_PREVIOUS_COMMIT not set" unless="env.GIT_PREVIOUS_COMMIT"/>
<!-- Prior successful commit may not exist - this MUST BE OPTIONAL -->
<!-- <fail message="GIT_PREVIOUS_SUCCESSFUL_COMMIT not set" unless="env.GIT_PREVIOUS_SUCCESSFUL_COMMIT"/> -->
</target>
<!-- Check environment variables in all builds -->
<target name="check-git-env-vars" description="Check all git env vars" depends="check-non-initial-build" if="env.JENKINS_URL">
<echo>env.WORKSPACE is ${env.WORKSPACE}</echo>
<echo>env.GIT_AUTHOR_EMAIL is ${env.GIT_AUTHOR_EMAIL}</echo>
<echo>env.GIT_AUTHOR_NAME is ${env.GIT_AUTHOR_NAME}</echo>
<echo>env.GIT_BRANCH is ${env.GIT_BRANCH}</echo>
<echo>env.GIT_COMMIT is ${env.GIT_COMMIT}</echo>
<echo>env.GIT_COMMITTER_EMAIL is ${env.GIT_COMMITTER_EMAIL}</echo>
<echo>env.GIT_COMMITTER_NAME is ${env.GIT_COMMITTER_NAME}</echo>
<echo>env.GIT_LOCAL_BRANCH is ${env.GIT_LOCAL_BRANCH}</echo>
<echo>env.GIT_URL is ${env.GIT_URL}</echo>
<echo>GIT_ env var checks all passed</echo>
<fail message="GIT_AUTHOR_EMAIL not set" unless="env.GIT_AUTHOR_EMAIL"/>
<fail message="GIT_AUTHOR_NAME not set" unless="env.GIT_AUTHOR_NAME"/>
<fail message="GIT_BRANCH not set" unless="env.GIT_BRANCH"/>
<fail message="GIT_COMMIT not set" unless="env.GIT_COMMIT"/>
<fail message="GIT_COMMITTER_EMAIL not set" unless="env.GIT_COMMITTER_EMAIL"/>
<fail message="GIT_COMMITTER_NAME not set" unless="env.GIT_COMMITTER_NAME"/>
<fail message="GIT_LOCAL_BRANCH not set" unless="env.GIT_LOCAL_BRANCH"/>
<fail message="GIT_URL not set" unless="env.GIT_URL"/>
</target>
<!-- Synchronize repositories -->
<target name="sync" description="Synchronize git repositories">
<git command="pull">
<args>
<arg value="--all"/>
<arg value="--prune"/>
</args>
</git>
</target>
<target name="increment" description="Increment build number">
<exec executable="hostname" outputproperty="increment.hostname"/>
<git command="pull">
<args>
<arg value="--all"/>
</args>
</git>
<buildnumber/>
<git command="commit">
<args>
<arg value="-m"/>
<arg value="[${ant.project.name}] ${user.name} on ${increment.hostname} build++, was ${build.number}"/>
<arg value="build.number"/>
</args>
</git>
</target>
<target name="increment-and-push" depends="increment" description="Increment build number and push to remote repository">
<git command="push"/>
</target>
<!-- Info about this repository -->
<target name="info" description="Report info about this repo">
<echo>java is ${java.version}</echo>
<echo>user dir is ${user.dir}</echo>
<git command="branch" />
<!-- JENKINS-41906 reports that master branch built without any commits.
This reports commits in the changeset for this build -->
<echo>Displaying ${changeLogCount} git log messages in changeset for this build - CHANGESET_SIZE=${env.CHANGESET_SIZE}</echo>
<git command="log">
<args>
<arg value="-n"/>
<arg value="${changeLogCount}"/>
</args>
</git>
<echo>End of ${changeLogCount} git log messages in changeset for this build</echo>
</target>
<!-- From https://gist.github.com/davejlong/874521 -->
<macrodef name="git">
<attribute name="command" />
<attribute name="dir" default="" />
<element name="args" optional="true" />
<sequential>
<echo message="git @{command}" />
<exec executable="git" dir="@{dir}">
<arg value="@{command}" />
<args/>
</exec>
</sequential>
</macrodef>
</project>