Jenkins Pipeline 流水线
Publish over SSH 将jar上传到远程 Docker 服务器、执行编译命令生成镜像、将镜像上传到阿里仓库
注意在运行 docker 命令前,要先切换一下 目录,如何会在 当前SSH远程的用户目录下执行,找不到 docker file
cd /opt/jenkins/PipelineDemo
docker build -t registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:4.0 .
docker login -u hi2ID@aliyun.com -p 密码 registry.cn-shanghai.aliyuncs.com
docker push registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:4.0
pipeline {
agent any
stages {
stage('上传文件') {
steps {
sshPublisher(publishers: [sshPublisherDesc(configName: 'DockerPublishSSH', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'PipelineDemo', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'target/demojenkins.jar'), sshTransfer(cleanRemote: false, excludes: '', execCommand: '''
cd /opt/jenkins/PipelineDemo
docker build -t registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:4.0 .
docker login -u hi帐号ID@aliyun.com -p 密码 registry.cn-shanghai.aliyuncs.com
docker push registry.cn-shanghai.aliyuncs.com/vipsoft/vipsoft:4.0''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'PipelineDemo', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'Dockerfile')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
echo '上传文件 SUCCESS'
}
}
}
}