npm config get registry // 查看npm当前镜像源
npm config set registry https://registry.npmjs.org
yarn config get registry // 查看yarn当前镜像源
yarn config set registry https://registry.yarnpkg.com
pipeline {
agent {
node {
label 'nodejs'
}
}
parameters {
string(name:'TAG_NAME', defaultValue: '', description:'')
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
quietPeriod(5)
timeout(time: 20, unit: 'MINUTES')
}
environment {
HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
KUBECONFIG_CREDENTIAL_ID = 'pipeline-user-kubeconfig'
APP_NAME = 'scp-ui-web'
}
stages {
stage ('checkout scm') {
steps {
checkout(scm)
script {
sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/docker/vue/Dockerfile'
}
}
}
stage ('build develop') {
when {
branch 'develop'
}
environment {
HARBOR_HOST = 'bytest-harbor.ur.com.cn'
HARBOR_NAMESPACE = 'scp-dev'
HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
}
steps {
container('nodejs') {
sh '''
yarn config set ignore-engines true
yarn config set registry https://registry.npmmirror.com
yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver
yarn config get registry
yarn cache dir
'''
sh 'yarn install --frozen-lockfile'
sh 'yarn build:new'
sh 'docker build -f `pwd`/Dockerfile -t $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER .'
withCredentials([usernamePassword(credentialsId : "$HARBOR_CREDENTIAL_ID" ,passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,)]) {
sh 'echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST -u "$HARBOR_USERNAME" --password-stdin'
sh 'docker push $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER'
}
}
}
}
stage ('build test') {
when {
branch 'test'
}
environment {
HARBOR_HOST = 'bytest-harbor.ur.com.cn'
HARBOR_NAMESPACE = 'scp-test'
HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
}
steps {
container('nodejs') {
sh '''
yarn config set ignore-engines true
yarn config set registry https://registry.npmmirror.com
yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver
yarn config get registry
yarn cache dir
'''
sh 'yarn install --frozen-lockfile'
sh 'yarn build:new'
sh 'docker build -f `pwd`/Dockerfile -t $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER .'
withCredentials([usernamePassword(credentialsId : "$HARBOR_CREDENTIAL_ID" ,passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,)]) {
sh 'echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST -u "$HARBOR_USERNAME" --password-stdin'
sh 'docker push $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER'
}
}
}
}
stage ('build pre') {
when {
branch 'pre'
}
environment {
HARBOR_HOST = 'hw-harbor.ur.com.cn'
HARBOR_NAMESPACE = 'scp-pre'
HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
}
steps {
container('nodejs') {
sh '''
yarn config set ignore-engines true
yarn config set registry https://registry.npmmirror.com
yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver
yarn config get registry
yarn cache dir
'''
sh 'yarn install --frozen-lockfile'
sh 'yarn build:new'
sh 'docker build -f `pwd`/Dockerfile -t $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER .'
withCredentials([usernamePassword(credentialsId : "$HARBOR_CREDENTIAL_ID" ,passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,)]) {
sh 'echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST -u "$HARBOR_USERNAME" --password-stdin'
sh 'docker push $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME.$TAG_NAME.$BUILD_NUMBER'
}
}
}
}
stage ('build release') {
when {
tag 'release-*'
}
environment {
HARBOR_HOST = 'hw-harbor.ur.com.cn'
HARBOR_NAMESPACE = 'scp-prod'
HARBOR_CREDENTIAL_ID = 'pipeline-user-harbor'
}
steps {
container('nodejs') {
sh '''
yarn config set ignore-engines true
yarn config set registry https://registry.npmmirror.com
yarn config set chromedriver_cdnurl https://npmmirror.com/mirrors/chromedriver
yarn config get registry
yarn cache dir
'''
sh 'yarn install --frozen-lockfile'
sh 'yarn build:new'
sh 'docker build -f `pwd`/Dockerfile -t $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME-$BUILD_NUMBER .'
withCredentials([usernamePassword(credentialsId : "$HARBOR_CREDENTIAL_ID" ,passwordVariable : 'HARBOR_PASSWORD' ,usernameVariable : 'HARBOR_USERNAME' ,)]) {
sh 'echo "$HARBOR_PASSWORD" | docker login $HARBOR_HOST -u "$HARBOR_USERNAME" --password-stdin'
sh 'docker push $HARBOR_HOST/$HARBOR_NAMESPACE/$APP_NAME:$BRANCH_NAME-$BUILD_NUMBER'
}
}
}
}
stage('deploy to develop') {
when {
branch 'develop'
}
environment {
NAMESPACE = 'scp-dev'
HARBOR_HOST = 'bytest-harbor.ur.com.cn'
HARBOR_NAMESPACE = 'scp-dev'
}
steps {
container ('nodejs') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')])
{
sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/deploy/scp/vue/dev/deployment.yaml'
sh 'envsubst < `pwd`/deployment.yaml | cat -'
sh 'envsubst < `pwd`/deployment.yaml | kubectl apply -f -'
}
}
}
}
stage('deploy to test') {
when {
branch 'test'
}
environment {
NAMESPACE = 'scp-test'
HARBOR_HOST = 'bytest-harbor.ur.com.cn'
HARBOR_NAMESPACE = 'scp-test'
}
steps {
container ('nodejs') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')])
{
sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/deploy/scp/vue/dev/deployment.yaml'
sh 'envsubst < `pwd`/deployment.yaml | cat -'
sh 'envsubst < `pwd`/deployment.yaml | kubectl apply -f -'
}
}
}
}
stage('deploy to pre') {
when {
branch 'pre'
}
environment {
NAMESPACE = 'scp-pre'
HARBOR_HOST = 'hw-harbor.ur.com.cn'
HARBOR_NAMESPACE = 'scp-pre'
}
steps {
container ('nodejs') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')])
{
sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/deploy/scp/vue/pre/deployment.yaml'
sh 'envsubst < `pwd`/deployment.yaml | cat -'
sh 'envsubst < `pwd`/deployment.yaml | kubectl apply -f -'
}
}
}
}
stage ('deploy release') {
when {
tag 'release-*'
}
environment {
NAMESPACE = 'scp-prod'
HARBOR_HOST = 'hw-harbor.ur.com.cn'
HARBOR_NAMESPACE = 'scp-prod'
}
steps {
container ('nodejs') {
withCredentials([
kubeconfigFile(
credentialsId: env.KUBECONFIG_CREDENTIAL_ID, variable: 'KUBECONFIG')])
{
sh 'wget http://192.168.13.78/paas-pub/pipeline/-/raw/master/deploy/scp/vue/prod/deployment.yaml'
sh 'envsubst < `pwd`/deployment.yaml | cat -'
sh 'envsubst < `pwd`/deployment.yaml | kubectl apply -f -'
}
}
}
}
}
}