-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjenkins.gdsl
127 lines (111 loc) · 4.36 KB
/
jenkins.gdsl
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
120
121
122
123
124
125
126
127
/*
Author: Gary Clayburg
This file allows IntelliJ IDEA to perform basic syntax checking and code completion for
Jenkins workflow groovy scripts. https://github.com/jenkinsci/workflow-plugin
These methods are supported
sh
readFile
node
echo
Usage:
1. Place this file somewhere in your classpath for the your IntelliJ project
2. You may see a note in IntelliJ IDEA that says "DSL descriptor file has been changed and isn't currently executed." If you see this, click the "Activate back" button.
3. Your jenkins workflow plugin groovy script should now offer quick Javadoc for supported build steps (sh,readFile,node,echo) and basic autocompletion hints
More background on IntelliJ and groovy DSL support here:
https://confluence.jetbrains.com/display/GRVY/Scripting+IDE+for+DSL+awareness
*/
// Create context for Groovy script files which names end with .groovy
// These definitions allow IntelliJ to autocomplete these variable names injected into groovy scripts/classes.
//def groovyContext = context(filetypes: ['groovy'], scope: scriptScope(name: "flow.groovy")) //restrict these context hints to only files named flow.groovy
def groovyContext = context(filetypes: ['groovy'], scope: scriptScope())
contributor(groovyContext) {
//injected into all groovy scripts (not necessarily for groovy classes)
def shDoc = """
Execute a shell script on a Jenkins node
<br/>usage examples:<br/>
<pre>
sh("ls")
def tmpdir = "/tmp"
sh "ls -l \$tmpdir"
sh 'chmod 755 ./build.sh'
sh "./build.sh"
sh script: "ls -l /"
sh \"\"\" # multiline script
chmod 644 pom.xml
ls /
echo "user home directory is \$HOME"
\"\"\"
</pre>
"""
def shParams = [
parameter(name: 'script', type: String.name, doc: "Bourne shell script text"),
]
method name: "sh", namedParams: shParams, doc: shDoc
method name: "sh", params: [script: 'java.lang.String'], doc: shDoc
def echoDoc = """
Print message to Jenkins build log <br/>
<br/>
Parameters:<br/>
    <b>message</b> text of message<br/>
<br/>
<br/>
Usage examples:<br/>
<pre>
echo 'hello world'
echo('hi world')
echo message: \"verbose form of echo\"
</pre>
"""
def echoParams = [
parameter(name: 'message', type: String.name, doc: "message text to output to console")
]
method name: 'echo', params: [message: 'java.lang.String'], doc: echoDoc
method name: 'echo', namedParams: echoParams, doc: echoDoc
def nodeDoc = """
Allocates an executor on a node (typically a slave) and runs further code in the context of a workspace on that slave. <br/>
<br/>
Usage examples:<br/>
<pre>
node('testingSlaves') { //testingSlaves must be defined as Jenkins slave label
// some block
}
</pre>
<pre>
node() { // execute on any Jenkins slave
// some block
}
</pre>
"""
method name: "node", type: "void", params: [label: 'java.lang.String', closure: 'groovy.lang.Closure'], doc: nodeDoc
method name: "node", type: "void", params: [ closure: 'groovy.lang.Closure'], doc: nodeDoc
def readFileParams = [
parameter(name: 'file', type: String.name, doc: "relative or absolute filename of file to read"),
parameter(name: 'encoding', type: String.name, doc: "character encoding of file (optional)"),
]
def readFileDoc = """
Read a file from workspace with specified encoding file encoding<br/>
<br/>
Parameters:<br/>
    <b>file</b> the path of the file to read<br/>
    <b>encoding</b> character encoding of the file. The platform default is used if this param is not specified<br/>
<br/>
Usage examples:<br/>
<pre>
def str = readFile file: 'pom.xml', encoding : 'utf-8' //read utf-8 encoded file
</pre>
<pre>
def str = readFile file: 'pom.xml' //read with default encoding
</pre>
<pre>
def str = readFile 'pom.xml' //read with default encoding
</pre>
"""
method name: "readFile", type: "java.lang.String", namedParams: readFileParams, doc: readFileDoc
method name: "readFile", params: [file: "java.lang.String"], doc: readFileDoc
}
def nodeContext = context(filetypes: ['groovy'], scope: closureScope() )
contributor(nodeContext){
if (enclosingCall("node")) { //allows specified methods in node() closure. This is too restrictive when the node(){} exists in a parent method
// method name: "sh", params: [scriptText: "java.lang.String"], doc: "run a java shell script"
}
}