forked from liejuntao001/jenkins-k8sagent-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k8sagent_Jenkinsfile.groovy
55 lines (48 loc) · 1.19 KB
/
k8sagent_Jenkinsfile.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
#!/usr/bin/env groovy
def build_on_node = ''
def build_on_cloud = ''
def my_node = [:]
@Library("k8sagent") _
pipeline {
agent none
stages {
stage('init') {
steps {
script {
// Read from job config
if (!env.BUILD_ON_NODE) {
error "BUILD_ON_NODE must be defined"
}
build_on_node = env.BUILD_ON_NODE
build_on_cloud = env.BUILD_ON_CLOUD
if (!build_on_cloud) {
echo "BUILD_ON_CLOUD not defined, guess as kubernetes"
build_on_cloud = 'kubernetes'
}
// build_on_node could be adjusted dynamically based on conditions
my_node = k8sagent(name: build_on_node, cloud: build_on_cloud)
echo "build_on_node is $build_on_node"
echo "build_on_cloud is $build_on_cloud"
}
}
}
stage('call other') {
agent {
kubernetes(my_node as Map)
}
stages {
stage('pod Demo') {
steps {
script {
sh 'env'
}
container('pg') {
sh 'env'
sh 'su - postgres -c \'psql --version\''
}
}
}
}
}
}
}