diff --git a/Jenkinsfile.prod b/Jenkinsfile.prod new file mode 100644 index 0000000..235b035 --- /dev/null +++ b/Jenkinsfile.prod @@ -0,0 +1,94 @@ +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/my-resume.git', + quickFilterEnabled: true, + 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/my-resume.git' + ]] + ]) + sh ''' + set -eu + test -n "$RELEASE_TAG" + NORMALIZED_RELEASE_TAG="$(printf '%s' "$RELEASE_TAG" | sed 's/\\^{}$//')" + 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 + npm -v + ''' + } + } + + stage('Install') { + steps { + sh ''' + npm ci + ''' + } + } + + stage('Check') { + steps { + sh ''' + node -v + npm -v + ''' + } + } + + stage('Build') { + steps { + sh ''' + npm run build:prod + test -f dist/index.html + ''' + } + } + + stage('Deploy Production') { + steps { + sh 'sudo /usr/local/bin/deploy-my-resume-from-jenkins "$WORKSPACE"' + } + } + } +}