|NO.Z.00021|——————————|CloudNative|——|Jenkins&Jenkins配置.V11|——|Jenkins.凭证&任务|

一、创建credentials凭证
### --- 创建凭证:credentials
~~~     # 步骤1:

~~~     在 jenkins 中使用 git 插件从仓库中 pull 代码的时候会要求 jenkins 必须有 pull 权限(尤其是当git开启了ssh认证的时候),
~~~     在配置 jenkins job 的时候有以下这些方法配置 ssh key:
~~~     登陆 jenkins 服务器,切换到 jenkins 用户(wing直接使用的root账户),生成 ssh key,然后把 公钥添加到 git 服务器上.
~~~     su - jenkins //切换到 jenkins HOME 目录
~~~     ssh-keygen -t rsa  // 生成 ssh key, 复制 xxx.pub 公钥到 git 服务器上即可.
~~~     # 步骤2:在jenkins界面,依次点击: Credentials -> System -> Add domain: 

~~~     Domain Name:  填写你git服务器的地址,如 github.xxx.com(wing填写的IP地址,127.0.0.1)
~~~     Description: 随便写一点描述,如 This is the Credential for github
~~~     # 构建流程
~~~     ——>凭证配置界面
~~~     ——>凭证添加
~~~     ——>创建SSH类型的凭证
~~~     ——>点击 ok 后 Credential 就创建好了。如果你再新建 Job 就可以看到我们的 Credential 选项了:

~~~     # ——>凭证添加
~~~     点击 ok 后,再点击  “adding some credentials?”
~~~     进入页面后,可以选择 Username with password 或者 SSH Username with private key, 
~~~     根据你的情况选择,这里我们选择 Username with private key:
~~~     Username: 随便起一个名字,以便在创建 Job 的时候使用该 Credential 
~~~     Private Key:可以指定文件,也可以使用默认的 ~/.ssh,当然也可以直接将私钥复制粘贴到此处。 
~~~     Passphrase: 如果你在创建 ssh key 的时候输入了 Passphrase 那就填写相应的Passphrase,为空就不填写 
~~~     ID: 空 
~~~     Description: 空
二、创建任务
### --- 创建任务

~~~     创建任务:Dashboard——>新建任务——>
~~~     定义名称和类型:创建名称->选择maven项目->确定
~~~     设置maven:公有git仓库——>设置描述——>
~~~     选择版本控制器和仓库地址:https://github.com/bingyue/easy-springmvc-maven.git
~~~     注:如果是私有仓库,这里需要建立credentials身份认证
~~~     设置触发器(保持默认)    
~~~     设置构建(编译打包)
~~~     注:手动添加Goals and options
~~~     注:clean package -Dmaven.test.skip=true
~~~     构建后操作 
~~~     注:在构建后设置中 选择:(send build artifacts over ssh)通过SSH发送构建工件 点击-》增加构建后操作
~~~     构建后操作说明
~~~     私有git仓库(略):私有仓库源码管理:如果是私有仓库:地址要这样写



三、构建后操作说明
### --- tomcat说明
~~~     因为之前的配置会默认出现tomcat业务服务器的名字

name:tomcat     
### --- source file target/*.war
### --- 构建之后,在jenkins服务器上是可以自动看到war包的。(该路径不需要创建)

[root@server11 ~]# ls /root/.jenkins/jobs/yanqitest/builds/target/*.war
Remove prefix                           // 自动删除路径前缀(不需要创建路径前缀)
Remote directory
### --- tomcat业务服务器上的路径,需要提前在10.10.10.12(tomcat)上创建该目录。
~~~     用来存放网站源代码。(需要后台创建)
### --- 创建文件夹

[root@server12 ~]# mkdir -p /jenkins/war
[root@server12 ~]# ll /jenkins/war/
total 0
 
Exec command    
tomcat(10.10.10.12// 在接收到源码之后的自定义动作。
### --- 比如:将源码拷贝到网站的主目录(/jenkins),
~~~     并执行一些其他操作如重启服务器等(或创建文件touch)(需要后台创建)

[root@server12 ~]# mkdir  /jenkins/sh
[root@server12 ~]# vim /jenkins/sh/deploy.sh
#!/bin/bash
touch /root/www.yanqi.com
[root@server12 ~]# chmod +x /jenkins/sh/deploy.sh
四、私有git仓库(略):私有仓库源码管理:如果是私有仓库:地址要这样写

附录一:git仓库报错排查
### --- 报错现象
~~~     如果是私有库,必须添加一个Credentials

Failed to connect to repository : Command "/usr/local/git/bin/git -c core.askpass=true ls-remote -h http://www.xxx.com/gitlab/root/test.git HEAD" returned status code 128:
stdout: 
stderr: fatal: Unable to find remote helper for 'http'
~~~     # OR
Failed to connect to repository : Command "git ls-remote -h git@xxxxx.com:xxx/dev_test.git HEAD" returned status code 128:
stdout: 
stderr: Permission denied, please tryagain. 
Permission denied, please try again. 
Permission denied(publickey,gssapi-keyex,gssapi-with-mic,password). 
fatal: The remote end hung up unexpectedly原因:没有配置git的ssh key
### --- 解决方案
~~~     执行下面的命令,生成key
~~~     然后将~/.ssh/目录下的id_rsa.pub中的公钥,放到git的ssh key中。
~~~     再在Jenkins中创建新的Credentials。类型是SSH Username with private key。
~~~     Username使用ssh-keygen中用到的邮箱,
~~~     Private Key中选择“From the Jenkins master ~/.ssh”即可。修改后,问题解决。

[root@server11 ~]# ssh-keygen -t rsa -C "admin@example.com"

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(48)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示