7 Star 8 Fork 5

Jenkins中文社区 / wechat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Jenkinsfile.groovy 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
Zhao Xiaojie 提交于 2019-05-19 19:57 . [维护] 设置流水线参数
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
1
https://gitee.com/jenkins-zh/wechat.git
git@gitee.com:jenkins-zh/wechat.git
jenkins-zh
wechat
wechat
master

搜索帮助