You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.4 KiB
132 lines
4.4 KiB
pipeline {
|
|
agent {
|
|
node {
|
|
label 'nodejs'
|
|
}
|
|
}
|
|
|
|
parameters {
|
|
choice(
|
|
description: '是否需要构建测试版?',
|
|
name: 'isBuildDev',
|
|
choices: ['Yes', 'No']
|
|
)
|
|
|
|
choice(
|
|
description: '是否需要构建正式线?',
|
|
name: 'isBuildProd',
|
|
choices: ['Yes', 'No']
|
|
)
|
|
|
|
string(name:'TAG_NAME',defaultValue: '',description:'')
|
|
}
|
|
|
|
environment {
|
|
KUBECONFIG_CREDENTIAL_ID = 'charge-kubeconfig'
|
|
HARBOR_CREDENTIAL_ID = 'node-harbor'
|
|
REGISTRY_ALIYUN_ID = 'aliyun-registry-id-chengdu'
|
|
REGISTRY = 'yourdomain.com'
|
|
REGISTRY_ALIYUN = 'registry.cn-chengdu.aliyuncs.com'
|
|
REGISTRY_ALIYUN_NAMESPACE = 'ycharge'
|
|
HARBOR_NAMESPACE = 'ycharge'
|
|
APP_NAME = 'ms-manager-saas'
|
|
}
|
|
|
|
stages {
|
|
stage ('checkout scm') {
|
|
steps {
|
|
checkout(scm)
|
|
}
|
|
}
|
|
|
|
stage ('Prepare') {
|
|
steps {
|
|
container ('nodejs') {
|
|
echo 'Building..'
|
|
echo 'npm版本信息..'
|
|
sh 'npm --version'
|
|
sh 'npm config set registry https://registry.npm.taobao.org'
|
|
sh 'npm config get registry'
|
|
echo '编译工程....'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage ('Test') {
|
|
steps {
|
|
container ('nodejs') {
|
|
echo 'Testing..'
|
|
echo '单元测试....'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage ('npm install') {
|
|
steps {
|
|
container ('nodejs') {
|
|
echo '------------------- 安装依赖包 -------------------'
|
|
// sh 'npm rebuild node-sass'
|
|
sh 'npm install'
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
stage ('Build Dev & Push Harbor') {
|
|
steps {
|
|
container ('nodejs') {
|
|
script{
|
|
if(isBuildDev == 'Yes'){
|
|
echo '------------------- 编译测试环境 ------------------'
|
|
sh 'npm run build:sit'
|
|
|
|
echo '------------------- 打包镜像上传Harbor仓库 ------------------'
|
|
sh 'docker build -f Dockerfile -t $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
|
|
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$HARBOR_CREDENTIAL_ID" ,)]) {
|
|
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
|
|
sh 'docker push $REGISTRY/$HARBOR_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
stage('Deploy to dev') {
|
|
when{
|
|
branch 'master'
|
|
}
|
|
steps {
|
|
// input(id: 'deploy-to-dev', message: 'deploy to dev?')
|
|
kubernetesDeploy(configs: "deploy/**", enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
|
|
}
|
|
}
|
|
|
|
|
|
stage ('Build Prod & Push Aliyun') {
|
|
steps {
|
|
container ('nodejs') {
|
|
script{
|
|
if(isBuildProd == 'Yes'){
|
|
echo '------------------- 编译正式环境 ------------------'
|
|
sh 'npm run build'
|
|
|
|
echo '------------------- 打包镜像上传阿里云镜像仓库 ------------------'
|
|
sh 'docker build -f Dockerfile -t $REGISTRY_ALIYUN/$REGISTRY_ALIYUN_NAMESPACE/$APP_NAME:$TAG_NAME .'
|
|
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$REGISTRY_ALIYUN_ID" ,)]) {
|
|
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY_ALIYUN -u "$DOCKER_USERNAME" --password-stdin'
|
|
sh 'docker push $REGISTRY_ALIYUN/$REGISTRY_ALIYUN_NAMESPACE/$APP_NAME:$TAG_NAME'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|