代码拉取完成,页面将自动刷新
同步操作将从 opendevops/codo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env groovy
node {
def branchOrTagName = BRANCH_NAME
def publishContent = ''
def version = 'master.latest'
def project = 'codo'
def action = ''
def ssh = ''
def targetInternalHosts = ''
def buildNotifyList = 'hongyang.mi@traxretail.com'
def publishNotifyList = 'hongyang.mi@traxretail.com'
def from_user = 'jenkins@lenztechretail.com'
String[] branchArr = branchOrTagName.split("/")
if (branchArr.length > 0) {
branchOrTagName = branchArr[branchArr.length-1]
}
try {
stage('Prepare Env') {
echo '请输入环境参数......'
checkout scm
version = branchOrTagName + ".latest"
def vars = input message: '请输入部署的环境参数', parameters: [
text(defaultValue: '', description: '请输入这次部署更新的内容', name: 'publishContent'),
text(defaultValue: '8.141.145.53', description: '请输入这次部署机器', name: 'hostname'),
text(defaultValue: "${version}", description: '请输入这次部署使用的镜像版本', name: 'version'),
choice(choices: ['deploy'], description: '请选择本次操作', name: 'action')
]
publishContent = vars['publishContent']
hostname = vars['hostname']
version = vars['version']
action = vars['action']
print('本次发布镜像版本:' + version)
print('本次发布动作:' + action + '服务')
print('本次使用分支:' + branchOrTagName)
echo 'branchOrTagName......${branchOrTagName}'
}
stage('Deploy') {
echo '发布......'
if (currentBuild.result == null || currentBuild.result == 'SUCCESS') {
ssh = "ssh -o StrictHostKeyChecking=no -l root ${hostname} -p 7721"
sh "${ssh} 'mkdir /data/project/${project} -p '"
sh "scp -P7721 ./docker-compose.yml root@${hostname}:/data/project/${project}"
sh "scp -P7721 ./deploy.sh root@${hostname}:/data/project/${project}/"
sh "${ssh} 'cd /data/project/${project};sh deploy.sh'"
echo "构建完成"
}
}
stage('Clean WS') {
//cleanWs cleanWhenFailure: false, cleanWhenUnstable: false, deleteDirs: true, notFailBuild: true
}
} catch (e) {
print('CI/CD构建异常,发送错误邮件给' + buildNotifyList)
mail to: buildNotifyList,
from: "${from_user}",
subject: "【失败】api-service接口[api-service] CI构建通知",
body: "api-service 构建失败,请前往${BUILD_URL} 查看" +
"\n 分支:${branchOrTagName}" +
"\n 失败原因:${e.toString()}" +
"\n 主要变更如下:" + getChangeLogs()
throw e
}
}
@NonCPS
def getChangeLogs() {
String logs = ""
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
logs += "\n ${entry.author}: ${entry.msg} [time:${new Date(entry.timestamp)},commitId:${entry.commitId}]"
def files = new ArrayList(entry.affectedFiles)
for (int k = 0; k < files.size(); k++) {
def file = files[k]
logs += "\n\t${file.editType.name}=> ${file.path}"
}
}
}
return logs
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。