模仿 workadround (kubesphere/ks-devops#465 (comment)):
pipeline {
agent {
kubernetes {
inheritFrom 'nodejs base'
containerTemplate {
name 'nodejs'
image 'node:14.19.0'
}
}
}
stages {
stage('Clone repository') {
agent none
steps {
checkout([$class: 'GitSCM', branches: [
[name: 'main']
],
extensions: [
[$class: 'CloneOption', depth: 1, shallow: true]
], userRemoteConfigs: [
[url: 'https://github.com/johnniang/vue-sample']
]
])
}
}
stage('Run npm install') {
steps {
container('nodejs') {
sh 'npm install'
}
}
}
stage('Run test') {
steps {
container('nodejs') {
sh 'npm run test'
}
}
}
stage('Run build') {
steps {
container('nodejs') {
sh 'npm run build'
}
}
}
stage('Archive artifacts') {
steps {
container('base') {
sh 'zip -r dist.zip dist/'
}
archiveArtifacts 'dist.zip'
}
}
}
}