Files
role-user/Jenkinsfile.prod
T
2026-06-05 14:45:44 +08:00

106 lines
2.5 KiB
Plaintext

pipeline {
agent any
parameters {
gitParameter(
name: 'RELEASE_TAG',
type: 'PT_TAG',
tagFilter: 'v*',
branchFilter: 'origin/(.*)',
sortMode: 'DESCENDING_SMART',
selectedValue: 'TOP',
useRepository: 'http://127.0.0.1:3001/my-project/role-user.git',
quickFilterEnabled: false,
listSize: '10',
requiredParameter: true,
description: '请选择要部署到生产环境的 Git Tag。列表自动来自当前项目仓库,生产只能从 Tag 发布。'
)
}
environment {
CI = 'true'
}
options {
timestamps()
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '10'))
}
stages {
stage('Checkout Tag') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
userRemoteConfigs: [[
url: 'http://127.0.0.1:3001/my-project/role-user.git'
]]
])
sh '''
set -eu
test -n "$RELEASE_TAG"
NORMALIZED_RELEASE_TAG="$(printf '%s' "$RELEASE_TAG" | sed 's/\\^{}$//')"
case "$NORMALIZED_RELEASE_TAG" in
v[0-9A-Za-z._-]*) ;;
*) echo "Invalid release tag: $NORMALIZED_RELEASE_TAG"; exit 2 ;;
esac
if ! git ls-remote --exit-code --tags origin "refs/tags/$NORMALIZED_RELEASE_TAG" >/dev/null; then
echo "Release tag does not exist in repository: $NORMALIZED_RELEASE_TAG"
exit 3
fi
echo "Deploying production tag: $NORMALIZED_RELEASE_TAG"
git fetch --tags --force
git checkout -f "refs/tags/$NORMALIZED_RELEASE_TAG"
git describe --tags --exact-match HEAD
'''
}
}
stage('Env') {
steps {
sh '''
git --version
node -v
corepack --version
corepack enable
corepack prepare pnpm@11.5.0 --activate
pnpm -v
'''
}
}
stage('Install') {
steps {
sh '''
pnpm install --frozen-lockfile
'''
}
}
stage('Check') {
steps {
sh '''
pnpm typecheck
'''
}
}
stage('Build') {
steps {
sh '''
pnpm build:prod
test -f .next/standalone/server.js
test -d .next/static
'''
}
}
stage('Deploy Production') {
steps {
sh 'sudo /usr/local/bin/deploy-role-user-from-jenkins "$WORKSPACE"'
}
}
}
}