概述
企业级流水线的虚拟机部署一般是采用 Publish Over SSH插件。需要安装密钥,并且把公钥拷贝到部署服务器上。
配置
1.密钥生成:
ssh-keygen
2.拷贝公钥
ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.9
3.安装 Jenkins 插件
普通机器部署一般是采用 Publish Over SSH插件。Publish Over SSH是通过 SSH 当方式传输。
4.配置 Publish Over SSH插件连接远程机器
cat id_rsa
ssh server
实践:自由风格
git源码web服务器
实践:pipeline
pipeline{
agent any
environment {
PROJECT_NAME='html'
BUILD_NUMBER='html01'
}
stages{
stage("拉取代码"){
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: 'add573ff-c885-4dbc-ad82-81736763327b', url: 'git@gitlab.mycloud.com:test/html.git']]])
}
}
stage("部署代码"){
steps {
sshPublisher(
publishers: [
sshPublisherDesc(
configName: 'web01',
transfers: [
sshTransfer(
cleanRemote: false,
excludes: '',
execCommand: '''#!/bin/bash''',
execTimeout: 120000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '/web',
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: '**/**'
)
],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: false
)
]
)
}
}
}
post {
always {
emailext (
body: """
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>${PROJECT_NAME}-第${BUILD_NUMBER}次构建日志</title></head><body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"
offset="0"><table width="95%" cellpadding="0" cellspacing="0" style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif"><tr>(本邮件由系统自动发出,无需回复!)<br/>各位好,以下是${PROJECT_NAME}项目构建信息<br/><td><font color="#CC0000">构建结果 - ${BUILD_STATUS}</font></td></tr><tr><td><br/><b><font color="#0B610B">构建信息 - ${BUILD_STATUS}</font></b><hr size="2" width="100%" align="center" /></td></tr><tr><td><ul><li>项目名称:${PROJECT_NAME}</li><li>构建编号:第${BUILD_NUMBER}次构建</li><li>构建版本:2021.1.0.0</li><li>触发原因:${CAUSE}</li><li>构建状态:${BUILD_STATUS}</li><li>构建日志:<a href="${BUILD_URL}console">${BUILD_URL}console</a></li><li>构建地址:<a href="${BUILD_URL}">${BUILD_URL}</a></li><li>工作目录:<a href="${PROJECT_URL}ws">${PROJECT_URL}ws</a></li><li>项目地址:<a href="${PROJECT_URL}">${PROJECT_URL}</a></li><li><a href="http://1xx.1xx.3.xx:81xx/plateform-backend/report/interfaceReport/xxx/${BUILD_TIMESTAMP}/index.html" >查看测试报告</a></li></ul><h4><font color="#0B610B">测试结果</font></h4><hr size="2" width="100%" /><div><hr size="2" width="100%" />
$FAILED_TESTS<br/><h4><font color="#0B610B">变更记录</font></h4><hr size="2" width="100%" />变更明细:<a href="${PROJECT_URL}changes">${PROJECT_URL}changes</a><br/></td></tr></table></body></html>
""",
mimeType: 'text/html',
subject: '自动化构建报告:$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!',
to: 'hlyue6000@163.com'
)
}
}
}
post发邮件没跑通,需要调试一下。
网友评论