Jenkins Pipeline 流水线 - K8S kubectl 升级
credentialsId: 'K8SMaster'
pipeline {
agent any
stages {
stage('Remote SSH') {
steps {
script {
def remote = [:]
remote.name = 'Test'
remote.host = '172.16.3.181'
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: 'K8SMaster', passwordVariable: 'password', usernameVariable: 'username')]) {
remote.user = "${username}"
remote.password = "${password}"
}
sshCommand remote: remote, command: "kubectl version"
}
}
}
}
}
pipeline {
agent any
stages {
stage('Remote SSH') {
steps {
script {
def remote = [:]
remote.name = 'Test'
remote.host = '172.16.3.181'
remote.allowAnyHosts = true
withCredentials([usernamePassword(credentialsId: 'K8SMaster', passwordVariable: 'password', usernameVariable: 'username')]) {
remote.user = "${username}"
remote.password = "${password}"
}
sshCommand remote: remote, command: "kubectl set image deployment/javademo1 vipsoft=registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:4.0"
}
}
}
}
}
注意JDK
[root@k8smaster k8s]# tar -zxvf /opt/k8s/jdk-11.0.17_linux-x64_bin.tar.gz -C /opt/k8s
[root@k8smaster k8s]# mv jdk-11.0.17 jdk
[root@k8smaster k8s]# ll
总用量 166600
drwxr-xr-x. 9 root root 126 11月 2 15:54 jdk
-rw-r--r--. 1 root root 169251172 11月 1 16:39 jdk-11.0.17_linux-x64_bin.tar.gz
-rw-r--r--. 1 root root 1339992 11月 2 15:50 remoting.jar
[root@k8smaster k8s]#
pipeline {
agent none
stages {
stage('代理节点运行') {
agent { label 'K8SAgent' } //这边使用节点名称或节点标签,都可以运行
steps {
sh 'kubectl set image deployment/javademo1 vipsoft=registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:4.0'
echo '构建完成'
}
}
}
}