背景
需要Jenkins中切换多个Node,比如nodejs16和nodesjs18,所以在宿主机按照好这两个版本,然后再映射到Jenkins容器中
步骤
1.下载地址
放到
bash
cd /opt/soft/
2.解压
tar -xzvf node-v16.20.0-linux-x64.tar.gz
tar -xzvf node-v18.14.2-linux-x64.tar.gz
3重命名
752 mv node-v16.20.0-linux-x64 nodejs16
753 mv node-v18.14.2-linux-x64 nodejs18
4修改文件
nodejs16/lib/node_modules/npm/bin/npm-cli.js 和 npx-cli.js 的第一行#!/usr/bin/env node -> #!/usr/bin/env node16
nodejs18/lib/node_modules/npm/bin/npm-cli.js 和 npx-cli.js 的第一行#!/usr/bin/env node -> #!/usr/bin/env node18
5建立软连接
ln -s /opt/soft/nodejs16/bin/node16 /usr/local/bin
ln -s /opt/soft/nodejs18/bin/node18 /usr/local/bin
6检查安装成功
Jenkins映射
找到Node16的路径,在下边的文件中映射
bash
version: '3.4'
services:
jenkins:
image: jenkins/jenkins:2.418
container_name: jenkins
ports:
- "8080:8080"
deploy:
resources:
limits:
memory: 2048m
reservations:
memory: 512m
volumes:
- /docker/jenkins/data:/var/jenkins_home
- /etc/localtime:/etc/localtime
- /usr/local/jdk17:/usr/local/jdk17
- /opt/moudle/jdk1.8.0_212:/opt/moudle/jdk1.8.0_212
- /opt/soft/nodejs16/bin:/opt/soft/nodejs16/bin
- /opt/soft/nodejs18/bin:/opt/soft/nodejs18/bin
restart: always
network_mode: host