jenkins安装sshPublishe插件配置ssh
生成流水线
片段
stage('Deploy') {
steps {
sshPublisher(publishers: [sshPublisherDesc(configName: 'aws', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'free -m; ifconfig', execTimeout: 300, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
}
}
}
}
}
完整pipeline
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
metadata:
labels:
some-label: jenkins
spec:
containers:
- name: docker
image: registry-intl.cn-shenzhen.aliyuncs.com/sztest/sz:dockerding
command:
- dockerd
- --host=unix:///var/run/docker.sock
- --host=tcp://0.0.0.0:8000
securityContext:
privileged: true
tty: true
- name: kubectl
image: registry.cn-shenzhen.aliyuncs.com/jbjb/csi:kubectl
command:
- cat
tty: true
- name: golang
image: golang:1.17.8-alpine3.15
command:
- cat
tty: true
- name: agent
image: registry-intl.cn-shenzhen.aliyuncs.com/sztest/sz:inbound-agent
command:
- cat
tty: true
'''
}
}
environment {
name="gaservers"
image="regiliyuncs.com/sztest/sz:${name}$BUILD_ID"
}
options{
timestamps ()
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '8'))
}
stages {
stage('Get Code && Build Package') {
steps {
container('golang') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'gitpull', url: 'https://g.gonga.cc/ga/ga_server_new.git']]])
sh '''
go build -o server .
'''
}
}
}
stage('Docker Build') {
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId: 'dockers', passwordVariable: 'Password', usernameVariable: 'Username')]) {
sh '''
docker login -u$Username -p$Password registry-intl.cn-shenzhen.aliyuncs.com
docker build -t ${image} -f Dockerfile-k8s .
docker push ${image}
echo ${image}
docker rmi ${image}
'''
}
}
}
}
stage('Deploy') {
steps {
sshPublisher(publishers: [sshPublisherDesc(configName: 'aws', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'free -m; ifconfig', execTimeout: 300, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
}
}
}
}
}