feature: 上传项目
This commit is contained in:
commit
83c9f7ce05
18
resources/notify/feishu/post.json
Normal file
18
resources/notify/feishu/post.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
\"msg_type\": \"post\",
|
||||
\"content\": {
|
||||
\"post\": {
|
||||
\"zh_cn\": {
|
||||
\"title\": \"$title\",
|
||||
\"content\": [
|
||||
[
|
||||
{
|
||||
\"tag\": \"text\",
|
||||
\"text\": \"$message\"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
vars/buildWeixin.groovy
Normal file
34
vars/buildWeixin.groovy
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
def call (Map config = [:]) {
|
||||
echo "--> 构建开始"
|
||||
def privateKey = config.privateKey // 小程序秘钥(仅第一次构建或修改秘钥时提供)
|
||||
def appId = config.appId // 小程序appId
|
||||
|
||||
def privatePath = "wx.${appId}.key"
|
||||
// 1. 检查appId
|
||||
if (!appId) {
|
||||
currentBuild.description = """
|
||||
<p style="color: red;">未找到appId, 请输入appId</p>
|
||||
"""
|
||||
error "--> 未找到appId"
|
||||
}
|
||||
// 2. 检查小程序授权秘钥(用于miniprogram-ci鉴权)
|
||||
// 2.1 将用户传入的秘钥写入工作目录
|
||||
if (privateKey) {
|
||||
writeFile encoding: "utf-8", file: privatePath, text: privateKey
|
||||
echo "--> 成功写入${appId}授权信息"
|
||||
}
|
||||
// 2.2 检查工作目录是否有秘钥
|
||||
if (!fileExists(privatePath)) {
|
||||
currentBuild.description = """
|
||||
<p style="color: red;">未找到${appId}授权信息, 请输入授权信息</p>
|
||||
"""
|
||||
error "--> 未找到${appId}授权信息"
|
||||
}
|
||||
// 3. 编译项目
|
||||
sh """
|
||||
rm -rf node_modules
|
||||
npm install --registry=https://registry.npmmirror.com
|
||||
npm run build:mp-weixin
|
||||
"""
|
||||
echo "--> 构建成功"
|
||||
}
|
||||
15
vars/notityFeishu.groovy
Normal file
15
vars/notityFeishu.groovy
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// 飞书消息推送, 向指定的飞书群发送消息
|
||||
def call (Map config = [:]) {
|
||||
def webhook = config.webhook
|
||||
def title = config.title
|
||||
def context = config.context
|
||||
def rawBody = libraryResource 'notify/feishu/post.json'
|
||||
def binding = [
|
||||
title: "${title}",
|
||||
message: "${context}"
|
||||
]
|
||||
def render = renderTemplate(rawBody,binding)
|
||||
sh """
|
||||
curl -X POST -H \"Content-Type: application/json\" --data \"${render}\" $webhook
|
||||
"""
|
||||
}
|
||||
27
vars/previewWeixin.groovy
Normal file
27
vars/previewWeixin.groovy
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
def call (Map config = [:]) {
|
||||
echo "--> 预览开始"
|
||||
def appId = config.appId // 小程序appId
|
||||
def page = config.page // 小程序预览页面路径
|
||||
def pageQuery = config.pageQuery // 小程序预览页面路径启动参数
|
||||
def robot = config.robot // ci机器人(1-30)处理预览缓存问题
|
||||
def branch = config.branch // 项目构建分支
|
||||
def deployEnv = config.deployEnv // 项目构建环境
|
||||
|
||||
def workspace = pwd() // 工作区地址
|
||||
def privatePath = "${workspace}/wx.${appId}.key" // 小程序秘钥地址
|
||||
def projectPath = "${workspace}/dist/build/mp-weixin" // 项目地址
|
||||
def artifactPath = "output/preview_${env.BUILD_NUMBER}.png" // 预览图片归档地址, 用于预览
|
||||
def outPath = "${workspace}/${artifactPath}" // 预览图片生成地址
|
||||
// 预览逻辑
|
||||
sh """
|
||||
mkdir -p output
|
||||
npm install miniprogram-ci@2.0.10 --save-dev --registry=https://registry.npmmirror.com
|
||||
node ./.ci/preview.js APPID=${appId} PROJECT_PATH=${projectPath} PRIVATE_KEY_PATH=${privatePath} PAGE=${page} PAGE_QUERY=${pageQuery} OUTPUT_PATH=${outPath} ROBOT=${robot}
|
||||
"""
|
||||
archiveArtifacts artifacts: artifactPath, fingerprint: true
|
||||
def previewPath = "https://yourciwebsite.com/job/${env.JOB_NAME}/${env.BUILD_NUMBER}/artifact/${artifactPath}"
|
||||
currentBuild.description = """
|
||||
<p>扫描我测试</p><p><img src="${previewPath}" alt="二维码" width="150" height="150" /></p><p>分支: ${branch},环境: ${deployEnv},机器人: ${robot}</p>
|
||||
"""
|
||||
echo "--> 预览成功"
|
||||
}
|
||||
19
vars/pullGitCode.groovy
Normal file
19
vars/pullGitCode.groovy
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// 拉取git仓库指定分支代码
|
||||
def call (Map config = [:]) {
|
||||
echo "--> 拉取代码开始"
|
||||
def branch = config.branch
|
||||
def url = config.url
|
||||
def credentialId = config.credentialId
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
branches: [[name: "*/${branch}"]],
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [],
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [[
|
||||
url: "${url}",
|
||||
credentialsId: "${credentialId}"
|
||||
]]
|
||||
])
|
||||
echo "--> 拉取代码成功"
|
||||
}
|
||||
5
vars/renderTemplate.groovy
Normal file
5
vars/renderTemplate.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def call(input, binding) {
|
||||
def engine = new groovy.text.GStringTemplateEngine()
|
||||
def template = engine.createTemplate(input).make(binding)
|
||||
return template.toString()
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user