forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
credential.groovy
60 lines (50 loc) · 1.52 KB
/
credential.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
/*
Format: Electric Flow DSL
File: credential.groovy
Description: an example on how to create a credential and use it in a step
or for impersonation
Note: for the impersonation to work, you need to enter a valid user/password
combination. The file 'foo' will be created with this user.
Command-line run instructions
-----------------------------
ectool evalDsl --dslFile credential.groovy
Run from Command Step
---------------------
Set shell to: ectool evalDsl --dslFile {0}
*/
def String _cred="userCred" // credentialName
def String _user="user" // User
def String _pwd="password" // Password
project("Hello Project") {
credential(_cred) {
userName = _user
password = _pwd
description = "generated by EF DSL"
}
procedure("credentialTest") {
// Create a step to use the credential
step ("retrieveLogin") {
// Attach the credential to this step
attachCredential(credentialName: _cred)
shell = 'ec-perl'
command = '''
use strict;
use ElectricCommander;
$|=1;
my $ec=new ElectricCommander({format=>'json'});
my $user=$ec->getFullCredential("''' + _cred + '''")->findvalue('//userName');
my $pass=$ec->getFullCredential("''' + _cred + '''")->findvalue('//password');
printf("User : $user\\n");
printf("Password: $pass\\n");
'''
}
// Create a step to use impersonation
step ("impersonation") {
credentialName = _cred // that is the impersonation
shell = 'bash'
command = '''touch foo
ls -ail
'''
}
}
}