基本操作和流程网上很多,本文仅记录碰到的问题和解决方法
因gitlab和gitlab-runner安装在了同一台服务器中,故在两台服务器分别安装时文章中的有些问题可能不会出现
使用关联方式安装nodejs时,gitlab的CI/CD中无法检测到node,也就无法使用npm,会报错:npm: command not found
// 下载解压,关联的方式:
wget https://registry.npmmirror.com/-/binary/node/v14.15.5/node-v14.15.5-linux-x64.tar.xz
xz -d node-v14.15.5-linux-x64.tar.xz
tar xf node-v14.15.5-linux-x64.tar //解压
ln -s /root/node-v14.15.5-linux-x64/bin/node /usr/local/bin/node //关联
ln -s /root/node-v14.15.5-linux-x64/bin/npm /usr/local/bin/npm //关联
后更改为 yum 安装,安装后能CI/CD能正常识别node和npm
// 安装nodejs和npm
sudo yum install nodejs
sudo yum install npm
gitlab-ci.yml中将dist文件复制到指定的目录中
// 最开始使用的指令
cp -r ./dist /root///将当前目录下的dist复制到root目录下
// CI/CD执行后提示:没有权限
cp: cannot stat ‘/root/dist’: Permission denied
// 添加上sudo(sudo命令是以root的身份执行command命令,但是环境变量还是当前用户的,执行目录也仍然是当前目录,即环境变量和执行目录都不会切换到root)
sudo cp -r ./dist /root //将当前目录下的dist复制到root目录下
//CI/CD执行后提示: 调用用户没有被授权使用sudo
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
解决办法:
在shell打开 sudoers 文件vim /etc/sudoers ,将下方内容添加到文件底部
gitlab-runner ALL=(ALL) NOPASSWD: ALL
wq保存退出时,提示该文件只读,使用wq!强制保存成功,再次执行CI/CD,dist文件复制成功