feature: 上传项目

This commit is contained in:
leonmin 2025-02-06 07:27:04 +08:00
commit 83c9f7ce05
6 changed files with 118 additions and 0 deletions

View 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
View 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
View 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
View 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
View 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 "--> 拉取代码成功"
}

View 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()
}