jenkins推送verdaccio
...小于 1 分钟
jenkins推送verdaccio
1.拉取代码
git branch: 'master', credentialsId: 'XXXXXXXXXXXXXXXXXXXXXXXXX', url: 'http://xxxx.xxxx.xxxx/xxx/demo.git'
2.安装依赖并构建
sh 'npm install --registry=https://registry.npmmirror.com/'
sh 'npm run build'
3.获取私服token
cat ~/.npmrc
4.推送到verdaccio
sh 'echo //xxx.xxxx.xxxx/:_authToken="xxxxxxxxx" > .npmrc' // 可在已登录设备获取
sh 'npm publish --registry http://xxx.xxxx.xxxx'
5.发送企业微信通知 (可选)
post {
always() {
wxwork(
robot: 'tears',
type: 'markdown',
text: [
"# 任务${JOB_NAME}",
"- 状态: ${currentBuild.result}",
"- 次数: ${BUILD_NUMBER}",
"- 执行人: ${BUILD_USER}",
"- [查看控制台](${BUILD_URL})"
]
)
}
}
6.完整配置 (可根据环境自行配置)
pipeline {
agent {
docker {
image 'node:14'
}
}
stages {
stage("拉取代码"){
steps {
git branch: 'master', credentialsId: 'XXXXXXXXXXXXXXXXXXXXXXXXX', url: 'http://xxxx.xxxx.xxxx/xxx/demo.git'
}
}
stage('打包项目') {
steps() {
sh 'npm install --registry=https://registry.npmmirror.com/'
sh 'npm run build'
}
}
stage('发布私服') {
steps {
sh 'echo //xxx.xxxx.xxxx/:_authToken="xxxxxxxxx" > .npmrc' // 可在已登录设备获取
sh 'npm publish --registry http://xxx.xxxx.xxxx'
}
}
}
post {
always() {
wxwork(
robot: 'xxxx',
type: 'markdown',
text: [
"# 任务${JOB_NAME}",
"- 状态: ${currentBuild.result}",
"- 次数: ${BUILD_NUMBER}",
"- 执行人: ${BUILD_USER}",
"- [查看控制台](${BUILD_URL})"
]
)
}
}
}
Powered by Waline v2.15.5