15 Star 6 Fork 21

终端组/bricks

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile 3.64 KB
一键复制 编辑 原始数据 按行查看 历史
pansinm 提交于 2018-11-21 13:59 . 更新 Jenkinsfile
pipeline {
agent {
node { label 'master' }
}
environment {
DINGDING_ROBOT_URL = "https://oapi.dingtalk.com/robot/send?access_token=${DINGDING_TOKEN}"
MASTER_WORKSPACE = "${WORKSPACE}"
}
stages {
stage('拉取文档') {
steps {
dir('site/build') {
withCredentials([usernamePassword(credentialsId: "${GIT_CREDENTIALS_ID}", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
git url: "https://${GIT_USERNAME}:${GIT_PASSWORD}@gitee.com/cassfrontend/bricks-docs.git"
sh 'ls'
}
}
}
}
stage('在docker构建') {
agent {
docker {
image 'node:10-alpine'
args '-v $MASTER_WORKSPACE:$MASTER_WORKSPACE'
}
}
stages {
stage('初始化') {
steps {
sh 'SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install --registry=https://registry.npm.taobao.org'
script {
env.BRICKS_VERSION = sh(returnStdout: true, script: 'node -pe "require(\'./package.json\').version"')
}
}
}
stage('单元测试') {
steps {
sh 'npm test'
}
}
stage('构建发布npm包') {
steps {
sh "echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > ~/.npmrc"
sh "npm run build"
sh "cp -rf site/build/* ${MASTER_WORKSPACE}/site/build"
sh "cp site/index.html ${MASTER_WORKSPACE}/site/build/v${BRICKS_VERSION}"
sh "npm publish --access public"
}
}
}
}
stage('发布文档') {
steps {
dir('site/build') {
sh("git add .")
sh("git commit -am 'auto commit'")
sh('git push origin master')
}
}
}
}
post {
success {
script {
def rawmsg = successNotifyData()
sh "curl -H 'Content-Type:application/json' -X POST --data '${rawmsg}' ${env.DINGDING_ROBOT_URL}"
}
}
failure {
script {
def rawmsg = failNotifyData()
sh "curl -H 'Content-Type:application/json' -X POST --data '${rawmsg}' ${env.DINGDING_ROBOT_URL}"
}
}
}
}
def failNotifyData() {
def changes = getChangeListByBuild(currentBuild)
def title = "${env.JOB_NAME} 构建失败[${env.BUILD_NUMBER}]"
def markdown = "### ${title}\n #### 新增特性 ${changes} \n #### 摘要 > buildUrl: ${env.BUILD_URL} \n > [点击查看](${env.BUILD_URL}/console)"
return buildJSON(title, markdown)
}
def successNotifyData() {
def changes = getChangeList()
def url = "${env.BUILD_URL}/artifact/artifacts/";
def title = "${env.JOB_NAME} 构建成功 [${env.BUILD_NUMBER}]"
def markdown = """
### ${title}
#### 新增特性:
${changes}
#### 构建结果:
> 发布版本: @casstime/bricks@${BRICKS_VERSION}
> 文档链接: https://cassfrontend.gitee.io/bricks-docs/v${BRICKS_VERSION}
"""
return buildJSON(title, markdown)
}
def buildJSON(title, markdown) {
return "{\"msgtype\":\"markdown\",\"markdown\":{\"title\":\"${title}\",\"text\":\"${markdown}\"}}"
}
def getChangeList() {
def text = ""
def build = currentBuild
text += getChangeListByBuild(build)
build = build.previousBuild
while (build && build.resultIsWorseOrEqualTo("UNSTABLE")) {
text += getChangeListByBuild(build)
build = build.previousBuild
}
return text
}
def getChangeListByBuild(build) {
def text = ""
for (changeSetList in build.changeSets) {
for (changeSet in changeSetList) {
text += "- ${changeSet.author.fullName} [${changeSet.msg}](https://gitee.com/cassfrontend/bricks/commit/${changeSet.commitId})\n"
}
}
return text
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/cassfrontend/bricks.git
git@gitee.com:cassfrontend/bricks.git
cassfrontend
bricks
bricks
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385