forked from concur/jenkins-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradle.groovy
119 lines (110 loc) · 3.29 KB
/
gradle.groovy
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
108
109
110
111
112
113
114
115
116
117
118
119
concurPipeline = new com.concur.Commands()
concurUtil = new com.concur.Util()
workflowDoc = '''
title: Gradle
overview: Execute any Gradle task.
additional_resources:
- name: Gradle Official
url: https://gradle.org
- name: Docker images
url: https://hub.docker.com/_/gradle/
tools:
- type: String
name: buildImage
description: Docker image containing Gradle and any other necessary tools for the project to build.
- type: String
name: binary
description: The Gradle binary to use, typically this would be `gradlew` or `gradle`.
default: ./gradlew
- type: String
name: task
description: The name of the task to execute, multiple tasks can be separated by a space.
default: build
- type: List
name: extraArgs
description: Any additional arguments to apply to the Gradle task.
full_example: |
pipelines:
tools:
branches:
patterns:
feature: .+
tools:
gradle:
buildImage: gradle:4.4-jdk9
branches:
feature:
steps:
- gradle:
- task:
binary: gradle
task: "test build publish"
'''
/*
description: Execute Gradle tasks.
parameters:
- type: String
name: buildImage
description: Docker image containing Gradle and any other necessary tools for the project to build.
- type: String
name: binary
description: The Gradle binary to use, typically this would be `gradlew` or `gradle`.
default: ./gradlew
- type: String
name: name
description: The name of the task to execute, multiple tasks can be separated by a space.
default: build
- type: List
name: extraArgs
description: Any additional arguments to apply to the Gradle task.
example: |
branches:
feature:
steps:
- gradle:
# Simple
- task:
# Advanced
- task:
binary: gradle
name: compile
*/
public task(Map yml, Map args) {
String dockerImage = args?.buildImage ?: yml.tools?.gradle?.buildImage
String gradleBinary = args?.binary ?: yml.tools?.gradle?.binary ?: './gradlew'
String taskName = args?.name ?: yml.tools?.gradle?.task ?: "build"
List taskArgs = args?.extraArgs ?: yml.tools?.gradle?.extraArgs
gradleTask = "${binary} ${taskName}"
if (extraArgs) {
gradleTask = "${gradleTask} ${extraArgs.join(" ")}"
}
assert dockerImage : "Workflows :: gradle :: task :: No [buildImage] provided in [tools.gradle] or as a parameter to the gradle.task step."
dockerImage = concurUtil.mustacheReplaceAll(dockerImage)
gradleTask = concurUtil.mustacheReplaceAll(gradleTask)
concurPipeline.debugPrint('Workflows :: gradle :: task', [
'args' : args,
'dockerImage' : dockerImage,
'gradleBinary': gradleBinary,
'taskArgs' : taskArgs
])
if(gradleTask) {
docker.image(dockerImage).inside {
sh gradleTask
}
}
}
/*
* Set the name of the stage dynamically.
*/
public getStageName(Map yml, Map args, String stepName) {
switch(stepName) {
case 'task':
def gradleCommand = args?.name ?: yml.tools?.gradle?.task ?: "build"
return "gradle: task: ${gradleCommand}"
}
}
public tests(Map yml, Map args) {
String workflowName = 'gradle'
println "Testing $workflowName"
}
return this;