https://www.notion.so/Parameters-and-Variables-in-Jenkinsfile-c42a2207b65f43df9ff6f78b2c4e17cb
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
import groovy.transform.Field
@Field def globalV = ""
def myFunc() {
echo "${globalV}" // The @Field is required for this variable in definition
}
node {
stage('Start') {
echo 'Testing..'
print params
if (params.b) {
echo 'has b'
}
if (b == 'true') {
echo 'b == true'
}
print 's:' + s
echo 's: ' + s
if (params.nn) {
echo 'has nn'
} else {
echo 'nn undefined'
}
}
stage('Build') {
echo 'Building..'
}
stage('Test') {
echo 'Testing..'
}
stage('Deploy') {
echo 'Deploying....'
}
stage ("Prompt for input") {
steps {
script {
env.USERNAME = input message: 'Please enter the username',
parameters: [string(defaultValue: '',
description: '',
name: 'Username')]
env.PASSWORD = input message: 'Please enter the password',
parameters: [password(defaultValue: '',
description: '',
name: 'Password')]
}
echo "Username: ${env.USERNAME}"
echo "Password: ${env.PASSWORD}"
}
}
}