jenkins官网 https://www.jenkins.io/download/
问题描述:
在使用Jenkins打包的时候,抛出这样的错,但JDK和Maven都是已经安装,没问题了的。其中Jenkins用的Pipline流水线来部署项目。
问题解决:
在使用Pipline部署项目的时候,本地区编译代码是自动使用 /usr/bin/java 的软连接来编译的,需要查看以下此软连接是不是指向了JAVA_HOME中 bin 目录下的 java命令,如果不是,直接删除掉此软连接,并新建:ln -s /usr/local/jdk8/bin/java /usr/bin/java
ln -s /usr/local/jdk8/bin/java /usr/bin/java
mvn clean install -pl starts-common -Dmaven.test.spik=true -Ptest -e
/var/lib/jenkins/workspace/starts_pipeline@tmp/durable-cb5301a6/script.sh: line 1: mvn: command not found
sudo ln -s /usr/local/apache-maven-3.6.3/bin/mvn /usr/local/bin/mvn
sudo ln -s /usr/local/apache-maven-3.6.3/bin/mvn /usr/bin/mvn
INFO: Retrying request to {}->unix://localhost:80
Dec 04, 2021 6:00:30 AM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.io.IOException) caught when processing request to {}->unix://localhost:80: Permission denied
Dec 04, 2021 6:00:30 AM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->unix://localhost:80
[WARNING] An attempt failed, will retry 1 more times
org.apache.maven.plugin.MojoExecutionException: Could not build image
at com.spotify.plugin.dockerfile.BuildMojo.buildImage (BuildMojo.java:185)
at com.spotify.plugin.dockerfile.BuildMojo.execute (BuildMojo.java:105)
at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute (AbstractDocker
chmod 777 /var/run/docker.sock
jenkins pipeline 配置publish over ssh bash 插件,远程部署,无法执行shell脚本
最开始是这样的报错下面这个,后面百度说可以看日志 verbose 变为true
sshPublisher(publishers: [sshPublisherDesc(configName: "master_service", transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/opt/jenkins_shell/deploy.sh $harbor_url $harbor_project $service $tag $port ", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: true)])
自己windos 上穿件的一个sh脚本,哭了…
1、重新在linux上创建脚本复制内容
2、改该shell脚本格式,方法如下:sed -i “s/\r//” deploy.sh。
这是一个坑 解决jenkins 秘钥存在但是新增的时候报错 说找不到秘钥
秘钥 首行:-----BEGIN OPENSSH PRIVATE KEY——
jenkins 版本在检验密钥时还不支持这种格式
ssh-keygen -m PEM -t rsa -b 4096
秘钥头部-----BEGIN RSA PRIVATE KEY-----
https://www.cnblogs.com/architectforest/p/13707244.html
https://www.bbsmax.com/A/n2d9qjnwdD/
jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [master_service]. Message [Auth fail]]
说明秘钥不对重新 复制,ssh-copy-id 机器IP
Credentials Binding Plugin 证书凭证管理 下载插件
#!/bin/bash
echo "编译构建开始!"
cd /var/lib/jenkins/workspace/auth/authentication
mvn clean install -Dmaven.test.spik=true -Ptest -e
echo "编译构建结束!"
clean install -Dmaven.test.skip=true -Ptest -e 失败有2种可能
一种是maven 仓库没有权限
chown -R jenkins:jenkins 仓库地址
clean install -pl $service -Dmaven.test.spik=true -Ptest -e
Extended Choice Parameter 多选参数插件
涉及到语法
插件下载 Pipeline
需要安装插件
Gitlab Hook GitLab
参照 我的另一篇帖子
cd /root/.ssh/
stage('编译构建代码/打包镜像、打标签、推送到镜像仓库') {
steps {
echo '编译构建代码---------------------------------->'
sh "mvn clean install -pl ${service} -Dmaven.test.spik=true -Ptest -e dockerfile:build"
//打标签
echo '开始打标签---------------------------------->'
sh "docker tag ${imagesName} ${harbor_url}/${harbor_project}/${imagesName}"
withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
// some block
echo '登录镜像仓库---------------------------------->'
sh "docker login -u ${username} -p ${password} ${harbor_url}";
//推送到镜像仓库
echo '开始推送到镜像仓库---------------------------------->'
sh "docker push ${harbor_url}/${harbor_project}/${imagesName}"
echo '镜像推送仓库成功---------------------------------->'
}
}
}