forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunProcedure.groovy
66 lines (56 loc) · 1.53 KB
/
runProcedure.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
/*
Format: Electric Flow DSL
File: runProcedure.groovy
Description: an example of a runprcoedure and wait for the job to finish
Command-line run instructions
-----------------------------
ectool evalDsl --dslFile runProcedure.groovy
Run from Command Step
---------------------
Set shell to: ectool evalDsl --dslFile {0}
*/
project ('Hello Project') {
procedure ('testRunProcedure') {
formalParameter('friend') {
required=1
defaultValue='Bob'
}
step ('helloFriend') {
command= '''printf("Hello $[friend] from EF DSL!\\n");
sleep(5);
exit(1);
'''
shell='ec-perl'
}
}
}
def resp
// Now let's run this newly created procedure
// This is in a transaction on purpose
transaction{
logFile = new File("/tmp/dsl.log")
logFile << "\n\n-------\n"
resp=runProcedure(
projectName: 'Hello Project',
procedureName: 'testRunProcedure',
actualParameter: [
friend: 'James',
]
)
}
// Now let's grab the jobId launched to run the procedure
def id=resp.jobId
// Let's wait for it to finish
logFile << "jobId:" + id.toString() + "\n"
def String status=''
while(status != "completed") {
// We need the polling in a different transaction started after
// the runProcedure one.
transaction{
status=getProperty(propertyName: 'status', jobId: id).value;
logFile << "status:" + status + "\n"
}
sleep (1000)
}
def String outcome=getProperty(propertyName: 'outcome', jobId: id).value;
logFile << "outcome:" + outcome + "\n"