Jenkins Pipeline 流水线 - 上传文件 Publish over SSH + Docker 编译 + 上传到阿里仓库
Jenkins Pipeline 流水线
Publish over SSH 将jar上传到远程 Docker 服务器、执行编译命令生成镜像、将镜像上传到阿里仓库
Publish over SSH Jar包上传、编译、上传
生成上传 jar 包脚本配置
生成上传 Dockerfile 脚本配置
注意在运行 docker 命令前,要先切换一下 目录,如何会在 当前SSH远程的用户目录下执行,找不到 docker file
增加编译Docker镜像命令
将镜像上传至阿里云
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'
}
}
}
}
本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/p/16851140.html