Jenkins报错解决
第一个问题解决方法:需要添加私钥 凭据第二个问题jenkins 加脚本 推送#!/bin/bashCOD_DIR=/var/lib/jenkins/workspace/dzpTIME=`date +%F-%H-%M-%S`IP=172.16.69.143WEB_DIR=/usr/share/nginxcd $COD_DIR && tar -zcf /tmp/web-${TIME}.
第一个问题
解决方法:
需要添加私钥 凭据
第二个问题
jenkins 加脚本 推送
#!/bin/bash
COD_DIR=/var/lib/jenkins/workspace/dzp
TIME=`date +%F-%H-%M-%S`
IP=172.16.69.143
WEB_DIR=/usr/share/nginx
cd $COD_DIR && tar -zcf /tmp/web-${TIME}.tar.gz ./*
scp /tmp/web-${TIME}.tar.gz $IP:$WEB_DIR
ssh root@$IP "cd $WEB_DIR && mkdir web-$TIME"
ssh root@$IP "cd $WEB_DIR && tar xf web-${TIME}.tar.gz -C web-$TIME && rm -rf web-${TIME}.tar.gz" &> /dev/null
ssh root@$IP "cd $WEB_DIR && rm -rf html && ln -s web-${TIME} html" &> /dev/null
第三个问题
jenkins掉用脚本失败
报错
+ bash /server/scripts/deploy.sh
Host key verification failed.
lost connection
Host key verification failed.
Build step ‘Execute shell’ marked build as failure
Finished: FAILURE
报错原因
a.jenkins普通用户无法执行某些系统命令;
b.没有为jenkins用户生成过密钥对,也没有将他的公钥拷到目标服务器上.
解决办法:
-
在安装jenkins后,系统生成了jenkins这个普通用户,但是在/etc/passwd中,他的shell是/bin/false,所以他不能登录系统,也没有家目录;
首先我们修改他的登录权限,将/bin/false改为/bin/bash,切换到jenkins用户,su - jenkins,他的终端显示为-bash-4.2$
jenkins❌997:995:Jenkins Automation Server:/var/lib/jenkins:/bin/bash -
生成jenkins用户密钥对
[root@bogon .ssh]# su - jenkins
-bash-4.2$ ssh-keygen -t rsa
回车-bash-4.2$ ssh-copy-id -i /var/lib/jenkins/.ssh/id_rsa.pub root@jenkins服务器IP
-
使用sudo提升普通用户权限
用viduso去修改文件,命令和命令之间要用逗号,最后用visudo -c检查语法是否出错.
visudo
root ALL=(ALL) ALL # 原有的
jenkins ALL=(ALL) NOPASSWD:/usr/bin/ssh,/usr/bin/rsync # 新增的最后就能够在jenkins中使用command命令执行了
这个时候可以执行了,但是还是会有错误,报错信息为
stderr: Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository
解决办法一
切换jenkins执行用户为root:
1.打开这个脚本(使用VIM或其他编辑器):
vim /etc/sysconfig/jenkins
2.找到这个$JENKINS_USER并改为“root”:
$JENKINS_USER=“root”更新以下目录用户
chown -R root:root /var/cache/jenkins
以及rpm包安装后jenkins的文件目录用户
chown -R root:root /usr/lib/jenkins/:jenkins安装目录,WAR包会放在这里。
chown -R root:root /etc/sysconfig/jenkins:jenkins配置文件,“端口”,“JENKINS_HOME”等都可以在这里配置。
chown -R root:root /var/lib/jenkins/ 默认的JENKINS_HOME。
chown -R root:root /var/log/jenkins/jenkins.log:Jenkins日志文件。systemctl restart jenkins
解决办法二
jenkins服务器上用 jenkins用户生成sshkey添加到git
问题:切换jenkins用户失败
解决:vim /etc/passwd,修改最后/bin/false为/bin/bash
1.切换为jenkins用户
执行ssh-keygen -t rsa
2.添加~/.ssh/id_rsa.pub 内容到gitlab
这个方法没有用,理论可行
第四个问题
插件缺失
Build when a change is pushed to GitLab. GitLab CI Service URL 插件
使用需要安装
GitLab Plugin Gitlab Hook Plugin 插件
第五个问题
Url is blocked: Requests to the local network are not allowed
持续集成 报错解决
Admin area => Settings => Network ,然后点击 Outbound requests 右边 的“expand”按钮,如下:
第六个问题
maven
安装
- wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
- tar xvf apache-maven-3.3.9-bin.tar.gz
- cd apache-maven-3.3.9
- mv apache-maven-3.3.9 /usr/local/
- ln -s /usr/local/apache-maven-3.3.9/ maven
- vim /etc/profile.d/env.conf
PATH=/usr/local/maven/bin:$PATH
MAVEN_HOME=/usr/local/maven
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64/jre
PATH=${PATH}:${MAVEN_HOME}/bin
测试
mvn -v 查看mvn版本,主要看JAVA_HOME的变量内容,是JDK的安装路径
git clone https://gitee.com/festone/my-hello-world.git
cd my-hello-world/
mvn my-hello-world/
报错
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-hello-world: Compilation failure No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
解决办法
yum install java-devel
换源打包
在/usr/local/maven/conf/settings.xml配置文件里的mirrot栏中添加以下
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
加快打包速度
第七个问题
maven nexus私服
安装好nexus启动
修改文件
vim /usr/local/maven/conf/settings.xml
找到标签
<server>
<id>my-nexus-releases</id>
<username>admin</username>
<password >admin123</password>
</server>
<server>
<id>my-nexus-snapshot</id>
<username>admin<username>
<password>admin123</password>
</server>
找到<mirrors>标签,添加镜像: .
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
找到<profiles>标签,添加仓库信息:
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>=central</id>
<url>http://172.16.69.142:8081/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://172.16.69.142:8081/repository/maven-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
激活仓库:
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
配置完成后保存,
并重启nexus服务。
声明式脚本式
脚本式语法格式:
pipeline{
agent any
stages{
stage("get code”){
steps{
echo "get code from scm"
}
}
stage(" package”){
steps{
echo "package code"
}
}
stage("deploy”){
steps{
echo "deploy package to node1"
}
}
}
}
pipeline{
agent any
stages{
stage("get code”){
steps{
echo "get code"
}
}
stage("unit test”){
steps{
echo "unit test"
}
}
stage("package”){
steps{
sh 'tar zcf /opt/web-${BUILD_ ID}.tar.gz ./* --exclude=./git --exclude=jenkinsfile'
}
}
stage("deploy”){
steps{
sh ‘ssh 10.0.0.8 “cd /usr/share/nginx && mkdir web-${BUILD_ID}"'
sh 'scp /opt/web-${BUILD_ID}.tar.gz 10.0.0.8:/usr/share/nginx/web-${BUILD_ID} '
sh 'ssh 10.0.0.8 "cd /usr/share/nginx/web-${BUILD_ID} && tar xf web-${BUILD_ID}.tar.gz && rm -rf web-${BUILD_ID}.tar.gz" ‘
sh 'ssh 10.0.0.8 "cd /usr/share/nginx && rm -rf html && ln -s web-${BUILD_ID} /usr/share/ nginx/html" '
}
}
}
}
更多推荐
所有评论(0)