yudong
你好,已上传完整的jenkinsfile,请帮看下
pipeline {
agent {
kubernetes {
inheritFrom 'nodejs base'
containerTemplate {
name 'nodejs'
image 'node:18.14.1'
}
}
}
stages {
stage('clone code') {
agent {
none {
label 'nodejs'
}
}
steps {
container('nodejs') {
git(url: '$GIT_URL', branch: '$BRANCH_NAME', credentialsId: 'git', changelog: true, poll: false)
}
}
}
stage('npm build') {
agent {
none {
label 'nodejs'
}
}
steps {
container('nodejs') {
sh '''
if (${IS_TAG}); then
git checkout ${TAG_NAME}
fi
for APPNAME in $APPNAME_LIST
do
cd ./mobile
npm install
npm run build:h5
npm install n -g
n 12.22.7
cd ../login
npm install
npm run build
cd ../web
npm install
npm run build
done
'''
}
}
}
stage('docker build') {
agent {
none {
label 'nodejs'
}
}
steps {
container('base') {
sh '''
if ($IS_TAG); then
VERSION_NAME=tag$TAG_NAME
else
VERSION_NAME=$BRANCH_NAME
fi
for APPNAME in $APPNAME_LIST
do
docker build -t $HARBOR_URL/$PROJECT_NAME/$APPNAME:$VERSION_NAME .
done
'''
}
}
}
stage('docker push') {
agent {
none {
label 'nodejs'
}
}
steps {
container('base') {
withCredentials([usernamePassword(credentialsId : 'harbor' ,passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,)]) {
sh 'echo "$DOCKER_PASSWORD" | docker login https://$HARBOR_URL -u "$DOCKER_USERNAME" --password-stdin'
sh '''
if (${IS_TAG}); then
VERSION_NAME=tag$TAG_NAME
else
VERSION_NAME=$BRANCH_NAME
fi
for APPNAME in $APPNAME_LIST
do
docker push $HARBOR_URL/$PROJECT_NAME/$APPNAME:$VERSION_NAME
done
'''
}
}
}
}
}
environment {
DOCKER_CREDENTIAL_ID = 'harbor'
KUBECONFIG_CREDENTIAL_ID = 'kubeconfig'
HARBOR_URL = 'www.baidu.com'
DOCKERHUB_NAMESPACE = 'smart'
SONAR_CREDENTIAL_ID = 'sonar-token'
}
}