目录
[1.Jenkins Build时的错误](#1.Jenkins Build时的错误)
[提问2:jenkins pipeline 类型为pipeline script from SCM时,如何配置npm源](#提问2:jenkins pipeline 类型为pipeline script from SCM时,如何配置npm源)
1.Jenkins Build时的错误
Jenkins小白,建立了一个Pipeline,类型为pipeline script from SCM,从SVN抓取代码发布。源代码里的Jenkinsfile是其他同事写好的(我不知道这个文件的作用)。
在构建build时,发生错误。

npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! network timeout at: https://registry.npmjs.org/pnpm
npm ERR! A complete log of this run can be found in:
npm ERR! /var/lib/jenkins/.npm/_logs/2025-01-07T03_51_51_161Z-debug-0.log
百度后了解到需要更改npm的源,开始各种搜索Jenkins里如何更改npm的源,无果。
2.百度文心快码AI智能体帮我解决
后在文心快码这个AI智能体中搜索了两个问题:
提问1:jenkins中如何配置npm的源
从回答中,看到下图部分:

提问2:jenkins pipeline 类型为pipeline script from SCM时,如何配置npm源
在这次对话中,AI给的回复中有一段(如下图),由此我想到了开头提到的Jenkinsfile,进而对Jenkinsfile进行修改,解决了这个问题。

3.最终解决方法-Jenkinsfile的修改
灰色部分为新增的两句:

python
stage('package') {
steps {
echo "开始打包执行npm install && npm run build"
sh "node -v"
sh "npm config set registry https://registry.npmmirror.com"
sh "npm config get registry"
sh "npm install -g pnpm@8.6.7"
sh "pnpm -v"
sh 'pnpm install --no-frozen-lockfile'
// sh "export NODE_OPTIONS=--max-old-space-size=10240"
sh "npm run build:dev"
echo "完成打包"
}
}
再次build时,成功迈过了这一步,如下:

4.感触
AI时代,且不说AI在编程方面会给程序员带来多少助力,至少在问题的搜索和建议方面,会给我们更多、更详细的答案。
为什么?因为人类很懒,解决完问题后,很少去详细的总结和记录。
所以,广大程序员,建议都用一用AI。
