forked from electric-cloud/DSL-Samples
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGetFullCredentialFromDSL.groovy
32 lines (28 loc) · 1.08 KB
/
GetFullCredentialFromDSL.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
/*
CloudBees CDRO DSL: Extract credential value in a DSL step
This example illustrates how to extract a password from a credential using the
getFullCredential() API from the Groovy DSL. The API is called from a procedure
step which has a credential parameter attached. When the procedure is run, the
user is prompted to enter credential values. The step stores the password to a
property--of course, in a real-world use case the password would not be exposed
in this way, but used to create another credential or to issue an API with
authentication.
*/
project "DSL-Samples",{
procedure 'Get full credentials with DSL', {
formalParameter 'cred', required: true, type: 'credential'
step 'Get password', {
shell = 'ectool evalDsl --dslFile'
command = '''\
property "/myJob/cred",
value: getFullCredential(
credentialName:"cred",
jobStepId: "$[/myJobStep/jobStepId]"
).password
'''.stripIndent()
attachParameter {
formalParameterName = "/projects/${projectName}/procedures/${procedureName}/formalParameters/cred"
}
}
}
}