Maven配置
如果你安装了Jenkins推荐安装的插件,那么Maven插件已经安装好了。
选择一个合适的Maven版本。
经过上面的配置,Jenkins会自动从Apache官网下载对应的Maven版本。
在流水线脚本中直接使用 maven 进行构建了。
pipeline {
agent any
tools {
maven 'maven3.8.4'
}
stages {
stage('Hello') {
steps {
echo 'Hello World'
sh 'mvn -v'
}
}
}
}
修改maven的setting文件。很多时候,Maven都会连接企业内部的私服,所以我们需要提供自定义的setting文件。
Jenkins会将所有的全局工具都下载到一个tools目录下,如果你没调整过Jenkins的home目录,那么应该是下面的目录。
bash-5.1# pwd
/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/maven3.8.4
所以,如果我们想用公司内部的setting文件,可以进入这个目录下的conf目录去修改setting文件。
node+npm私服配置
安装NodeJs
step1:安装NodeJs插件
step2:选择版本
注意:NodeJS 自动安装在Global npm packages to install 输入 淘宝镜像,提高安装速度
cnpm --registry=https://registry.npm.taobao.org
step3:在流水线中使用
pipeline {
agent any
tools {
nodejs "node17.3.0"
}
stages {
stage('Hello') {
steps {
echo 'Hello World'
sh 'node -v'
}
}
}
}
使用npm私服
step1:通过config-file-provider插件配置npm配置文件
config-file-provider这个插件一般情况下是已经安装好的。如果没装的话,自己先安装下。
step2:在流水线中使用
pipeline {
agent any
stages {
stage('Build') {
steps {
nodejs(nodeJSInstallationName: 'node17.3.0', configId: 'npm-private') {
sh 'npm -v'
sh 'npm install'
}
}
}
}
}
用好NodeJS这个插件,还可以实现很多功能:
- Provides NodeJS auto-installer, allowing to create as many NodeJS installations "profiles" as you want.
The auto-installer will automatically install a given version of NodeJS, on every jenkins agent where it will be needed- Allows to install globally some npm packages inside each installations, these npm packages will be made available to the PATH
- Allows to execute some NodeJS script, under a given NodeJS installation
- Allows use custom NPM user configuration file defined with config-file-provider plugin to setup custom NPM settings
- Add a lightweight support to DSL pipeline
- Force 32bit architecture
- Relocate npm cache folder using pre defined strategies
- Allow use of a mirror repo for downloading and installing NodeJS.