forked from mibexsoftware/bamboo-plan-dsl-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask.groovy
60 lines (51 loc) · 1.91 KB
/
Task.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
package ch.mibex.bamboo.plandsl.dsl.tasks
import ch.mibex.bamboo.plandsl.dsl.BambooFacade
import ch.mibex.bamboo.plandsl.dsl.BambooObject
import ch.mibex.bamboo.plandsl.dsl.NullBambooFacade
import ch.mibex.bamboo.plandsl.dsl.Validations
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
@EqualsAndHashCode(includeFields=true, excludes = ['metaClass'])
@ToString(includeFields=true)
abstract class Task extends BambooObject {
protected boolean enabled = true // we want tasks to be enabled by default
protected boolean isFinal
protected String description
protected String pluginKey
protected Task(BambooFacade bambooFacade, String pluginKey) {
super(bambooFacade)
this.pluginKey = pluginKey
}
protected Task(String pluginKey) {
this(new NullBambooFacade(), pluginKey)
}
protected abstract def Map<String, String> getConfig(Map<Object, Object> context)
/**
* Enable or disable this task.
*/
void enabled(boolean enabled = true) {
this.enabled = enabled
}
/**
* Final tasks are always executed even if a previous task fails.
*/
void isFinal(boolean isFinal = true) {
this.isFinal = isFinal
}
/**
* Task description.
*/
void description(String description) {
this.description = description
}
protected String getArtifactId(Map<Object, Object> context, String deployArtifactName, boolean v2 = false) {
def contextArtifacts = context['artifacts']
def artifact = contextArtifacts[deployArtifactName]
Validations.requireNotNullOrEmpty(
artifact, "artifact details for '$deployArtifactName' not found in task $pluginKey: " + context
)
def info = artifact.asType(ArtifactInfo)
def prefix = v2 ? 'v2:' : ''
"${prefix}${info.artifactId}:${info.taskId}:${info.transferId}:${info.name}".toString()
}
}