代码拉取完成,页面将自动刷新
同步操作将从 Jenkins中文社区/wechat 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
pipeline {
agent any
options {
disableConcurrentBuilds()
quietPeriod 30
}
stages{
stage("文章格式校验"){
when {
changeRequest target: 'master'
}
steps{
script{
withChangeSets(){
if(env.changePath != "" && env.changePath != null && env.changePath.endsWith(".md")) {
checkArticleMeta(env.changePath)
}
}
}
}
}
stage("preview"){
when {
changeRequest target: 'master'
}
steps{
script{
def branch = "wechat-$BRANCH_NAME"
branch = branch.toLowerCase()
def prNum = "$BRANCH_NAME".replace('PR-','')
build job: 'jenkins-zh/jenkins-zh/master', parameters: [string(name: 'previewUpstream', value: branch),string(name: 'previewUpstreamPR', value: prNum)]
pullRequest.createStatus(status: 'success',
context: 'continuous-integration/jenkins/pr-merge/preview',
description: 'Website preview',
targetUrl: "http://" + branch + ".preview.jenkins-zh.cn")
}
}
}
}
}
def checkArticleMeta(filePath){
def articleText = readFile encoding: 'UTF-8', file: filePath
def articleYamlText = getYamlMeta(articleText)
if(isEmpty(articleYamlText)){
error "cannot find the yaml meta from current article"
}
def articles = readYaml file: articleYamlText
def article = articles[0]
if(isEmpty(article.title) || isEmpty(article.description)
|| isEmpty(article.author) || isEmpty(article.poster)){
error "title, description, author or poster can not be empty"
}
if(!isEmpty(article.translator) && isEmpty(article.original)) {
error "current article is translated from the origin one, please provide the original link"
}
}
def isEmpty(str){
return str == "" || str == null
}
def getYamlMeta(txt){
def firstIndex = txt.indexOf('---')
if(firstIndex == -1){
return ""
}
def secondIndex = txt.indexOf('---', firstIndex + 3)
if(secondIndex == -1){
return ""
}
return txt.substring(firstIndex, secondIndex + 3)
}
// DSL withChangeSets has not been released, see also
// https://github.com/LinuxSuRen/change-handler
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。