更新构建文件使用分支和 Tag 模式 #8
Vendored
+100
-111
@@ -3,138 +3,127 @@ pipeline {
|
||||
|
||||
options {
|
||||
ansiColor('xterm')
|
||||
disableConcurrentBuilds()
|
||||
timeout(time: 30, unit: 'MINUTES')
|
||||
}
|
||||
|
||||
tools {
|
||||
jdk 'TemurinJDK-17'
|
||||
maven 'Maven 3.8.7'
|
||||
nodejs 'NodeJS 22.14.0'
|
||||
nodejs 'NodeJS 22.14.0'
|
||||
}
|
||||
|
||||
environment {
|
||||
|
||||
PRJ_NAME = 'docs-isharkfly-com'
|
||||
PRJ_VERSION = '0.0.1-SNAPSHOT'
|
||||
REPO_USERNAME = credentials('86617b35-b114-4604-b054-082c8638bf8e')
|
||||
REPO_PASSWORD = credentials('c96b3079-b141-43f0-b43a-c9c2adfb14ea')
|
||||
NODE_OPTIONS = '--openssl-legacy-provider'
|
||||
|
||||
// AWS
|
||||
AWS_ACCOUNT_ID = credentials('stonex_aws_account_id')
|
||||
AWS_REGION = 'us-east-1'
|
||||
AWS_ACCESS_KEY_ID = credentials('stonex_aws_access_key_id')
|
||||
AWS_SECRET_ACCESS_KEY = credentials('stonex_secret_access_key')
|
||||
|
||||
// AWS - ECR
|
||||
IMAGE_REPO_NAME = 'stonex/app-service'
|
||||
IMAGE_TAG = 'latest'
|
||||
REPOSITORY_URI = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${IMAGE_REPO_NAME}"
|
||||
|
||||
// 显式指定 wrangler 配置文件
|
||||
WRANGLER_CONFIG = 'wrangler.jsonc'
|
||||
// Cloudflare API Token(Jenkins Secret text 凭据,需要 Workers Scripts:Edit 权限)
|
||||
CLOUDFLARE_API_TOKEN = credentials('sharkdat-cloudflare-api-token')
|
||||
// Cloudflare Account ID(Secret text 凭据)。设置后 wrangler 不再调用 /memberships 查询账号,
|
||||
// 避免 token 缺少 Account 读取权限时报 "You may have incorrect permissions on your API token"
|
||||
CLOUDFLARE_ACCOUNT_ID = credentials('sharkdat-cloudflare-account-id')
|
||||
// 不让 wrangler 发送使用统计、不弹交互提示
|
||||
WRANGLER_SEND_METRICS = 'false'
|
||||
CI = 'true'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage("Configure"){
|
||||
steps {
|
||||
script {
|
||||
// This command should run on the agent to configure the git environment
|
||||
sh 'git config --global url."https://github.com/".insteadOf git://github.com/'
|
||||
sh '''
|
||||
set -eu
|
||||
corepack enable
|
||||
'''
|
||||
|
||||
}
|
||||
// git branch: 'main',
|
||||
// credentialsId: 'c9d0ec7c-0749-4588-8960-e96cab84d462',
|
||||
// url: 'https://src.isharkfly.com/USVisaTrack/Usvisatrack-Ui.git'
|
||||
}
|
||||
}
|
||||
|
||||
stage("Install") {
|
||||
stages {
|
||||
stage('Configure') {
|
||||
steps {
|
||||
sh 'git config --global url."https://github.com/".insteadOf git://github.com/'
|
||||
sh '''
|
||||
rm -rf node_modules
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm approve-builds --all
|
||||
set -eu
|
||||
corepack enable
|
||||
node --version
|
||||
pnpm --version
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build / Package') {
|
||||
steps {
|
||||
sh '''
|
||||
npx browserslist@latest --update-db
|
||||
npm run docs:build
|
||||
'''
|
||||
}
|
||||
}
|
||||
stage('Install') {
|
||||
steps {
|
||||
sh 'pnpm install --frozen-lockfile'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy to Cloudflare') {
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo 'Build VitePress docs ...'
|
||||
sh 'pnpm run docs:build'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy - CF') {
|
||||
steps {
|
||||
script {
|
||||
def branchArg = env.CHANGE_ID
|
||||
? "pr-${env.CHANGE_ID}"
|
||||
: env.BRANCH_NAME.replaceAll('/', '-')
|
||||
withEnv([
|
||||
'LANG=C.UTF-8',
|
||||
'LC_ALL=C.UTF-8',
|
||||
'NO_COLOR=1',
|
||||
'TERM=dumb'
|
||||
]) {
|
||||
// 部署消息:显示在 Cloudflare 控制台 → Worker → Deployments
|
||||
def shortSha = env.GIT_COMMIT ? env.GIT_COMMIT.take(7) : 'unknown'
|
||||
def deployMsg = "Jenkins ${env.JOB_NAME} #${env.BUILD_NUMBER} (${shortSha})"
|
||||
|
||||
if (env.BRANCH_NAME == 'main') {
|
||||
sh 'pnpm exec wrangler deploy'
|
||||
} else {
|
||||
sh "pnpm exec wrangler versions upload --preview-alias ${branchArg}"
|
||||
// Tag 构建:部署到 production 环境(wrangler.jsonc 中的 env.production)
|
||||
if (env.TAG_NAME?.trim()) {
|
||||
sh """
|
||||
pnpm exec wrangler deploy --config ${env.WRANGLER_CONFIG} --env production \
|
||||
--message '${deployMsg}' \
|
||||
--tag '${env.TAG_NAME}'
|
||||
"""
|
||||
return
|
||||
}
|
||||
|
||||
// main 分支:部署默认 Worker
|
||||
if (env.BRANCH_NAME == 'main') {
|
||||
sh """
|
||||
pnpm exec wrangler deploy --config ${env.WRANGLER_CONFIG} --env="" \
|
||||
--message '${deployMsg}' \
|
||||
--tag '${shortSha}'
|
||||
"""
|
||||
return
|
||||
}
|
||||
|
||||
// PR 或其他分支:上传 Preview Version,不影响线上流量
|
||||
def branchArg = env.CHANGE_ID
|
||||
? "pr-${env.CHANGE_ID}"
|
||||
: env.BRANCH_NAME
|
||||
|
||||
def previewAlias = branchArg
|
||||
.toLowerCase()
|
||||
.replaceAll(/[^a-z0-9-]+/, '-')
|
||||
.replaceAll(/^-+|-+$/, '')
|
||||
|
||||
// 打印当前 token 所属账号,便于排查 "Worker does not yet exist"(通常是账号不对)
|
||||
sh 'pnpm exec wrangler whoami'
|
||||
|
||||
sh """
|
||||
pnpm exec wrangler versions upload --config ${env.WRANGLER_CONFIG} --env="" \
|
||||
--preview-alias '${previewAlias}' \
|
||||
--message 'Jenkins ${env.JOB_NAME} #${env.BUILD_NUMBER}'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// stage('Build Docker') {
|
||||
// steps {
|
||||
// echo 'Build Docker ...'
|
||||
// sh 'docker image prune -f'
|
||||
// // sh 'docker build -f Dockerfile -t ${PRJ_NAME}:${PRJ_VERSION} --label ${PRJ_NAME} .'
|
||||
// sh 'docker build -f Dockerfile -t ${REPOSITORY_URI}:${IMAGE_TAG} --label ${PRJ_NAME} .'
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// stage('Docker Deploy - ECR') {
|
||||
// steps {
|
||||
// echo 'Deploying To Docker Repo....'
|
||||
// withCredentials([
|
||||
// [$class: 'AmazonWebServicesCredentialsBinding',
|
||||
// credentialsId: 'stonex-creds', // The ID from Step 2
|
||||
// accessKeyVariable: 'AWS_ACCESS_KEY_ID',
|
||||
// secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']
|
||||
// ]) {
|
||||
// // Authenticate Docker with ECR
|
||||
// sh "aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${REPOSITORY_URI}"
|
||||
//
|
||||
// // Push the built image
|
||||
// sh "docker push ${REPOSITORY_URI}:${IMAGE_TAG}"
|
||||
// }
|
||||
//
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// stage('Deploy Docker') {
|
||||
// steps {
|
||||
// echo 'Deploying To Docker Repo....'
|
||||
// sh 'docker tag ${PRJ_NAME}:${PRJ_VERSION} repo-docker.isharkfly.com/docker-hub/${PRJ_NAME}:${PRJ_VERSION}'
|
||||
// sh 'docker tag ${PRJ_NAME}:${PRJ_VERSION} repo-docker.isharkfly.com/docker-hub/${PRJ_NAME}:latest'
|
||||
//
|
||||
// sh 'docker login repo-docker.isharkfly.com --username ${REPO_USERNAME} --password ${REPO_PASSWORD}'
|
||||
// sh 'docker push repo-docker.isharkfly.com/docker-hub/${PRJ_NAME}:${PRJ_VERSION}'
|
||||
// sh 'docker push repo-docker.isharkfly.com/docker-hub/${PRJ_NAME}:latest'
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// stage('Deploy Server') {
|
||||
// steps {
|
||||
// echo 'Deploying To Server ....'
|
||||
// dir('deploy') {
|
||||
// sh 'ansible-playbook site.yml'
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
env.BUILD_STARTED_AT = new Date(currentBuild.startTimeInMillis)
|
||||
.format('yyyy-MM-dd HH:mm:ss z', TimeZone.getTimeZone('America/New_York'))
|
||||
|
||||
env.BUILD_DURATION_TEXT = currentBuild.durationString
|
||||
|
||||
emailext (
|
||||
mimeType: 'text/html; charset=UTF-8',
|
||||
subject: "Build ${currentBuild.currentResult}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
|
||||
body: '${DEFAULT_CONTENT}',
|
||||
from: '[email protected]',
|
||||
to: '[email protected]'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-1
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"$schema": "./node_modules/wrangler/config-schema.json",
|
||||
// VitePress 纯静态站点,使用 Cloudflare Workers Static Assets 托管(无 Worker 脚本)
|
||||
"name": "docs-isharkfly-com",
|
||||
"compatibility_date": "2025-11-01",
|
||||
"compatibility_date": "2026-06-25",
|
||||
"assets": {
|
||||
// vitepress build 默认输出目录(相对项目根目录)
|
||||
"directory": ".vitepress/dist",
|
||||
@@ -12,6 +13,23 @@
|
||||
// 允许 PR / 分支通过 versions upload 生成 Preview URL
|
||||
"preview_urls": true,
|
||||
|
||||
// 原 wrangler.toml 中的可观测性配置
|
||||
"observability": {
|
||||
"enabled": false,
|
||||
"head_sampling_rate": 1,
|
||||
"logs": {
|
||||
"enabled": true,
|
||||
"head_sampling_rate": 1,
|
||||
"persist": true,
|
||||
"invocation_logs": true
|
||||
},
|
||||
"traces": {
|
||||
"enabled": false,
|
||||
"persist": true,
|
||||
"head_sampling_rate": 1
|
||||
}
|
||||
},
|
||||
|
||||
"env": {
|
||||
// Tag 构建部署到此环境:Worker 名称为 docs-isharkfly-com-production
|
||||
"production": {
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
name = "docs-isharkfly-com"
|
||||
main = "docs/worker.js" # Path to your Worker script logic
|
||||
compatibility_date = "2026-06-25"
|
||||
|
||||
[assets]
|
||||
directory = "./.vitepress/dist"
|
||||
binding = "ASSETS"
|
||||
|
||||
[observability]
|
||||
enabled = false
|
||||
head_sampling_rate = 1
|
||||
|
||||
[observability.logs]
|
||||
enabled = true
|
||||
head_sampling_rate = 1
|
||||
persist = true
|
||||
invocation_logs = true
|
||||
|
||||
[observability.traces]
|
||||
enabled = false
|
||||
persist = true
|
||||
head_sampling_rate = 1
|
||||
Reference in New Issue
Block a user