-
Notifications
You must be signed in to change notification settings - Fork 402
Expand file tree
/
Copy pathwithCredentials_Jenkinsfile
More file actions
40 lines (35 loc) · 1.53 KB
/
withCredentials_Jenkinsfile
File metadata and controls
40 lines (35 loc) · 1.53 KB
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
pipeline {
agent any
stages {
stage("run") {
withCredentials([
usernamePassword( credentialsId: 'my_cred_id', usernameVariable: 'user', passwordVariable: 'pass' ),
string( credentialsId: 'docker_cred', variable: 'docker_pass' ),
string( credentialsId: 'ssh_cred', variable: 'ssh_pass' )
]) {
// Ensure values are set on entry
echo "User/Pass = $user/$pass"
echo "Docker = $docker_pass"
echo "SSH = $ssh_pass"
withCredentials([
usernamePassword( credentialsId: 'my_cred_id', usernameVariable: 'user', passwordVariable: 'pass' ),
string( credentialsId: 'docker_cred', variable: 'docker_pass' ),
string( credentialsId: 'ssh_cred', variable: 'ssh_pass' )
]) {
// Ensure nested values are in place
echo "Nested User/Pass = $user/$pass"
echo "Nested Docker = $docker_pass"
echo "Nested SSH = $ssh_pass"
}
// Ensure original values are restored
echo "Restored User/Pass = $user/$pass"
echo "Restored Docker = $docker_pass"
echo "Restored SSH = $ssh_pass"
}
// Ensure original state where the values are not set
echo "Cleared User/Pass = $user/$pass"
echo "Cleared Docker = $docker_pass"
echo "Cleared SSH = $ssh_pass"
}
}
}