久久国产乱子伦精品免费M,亚洲一区二区三区91,欧美国产在线视频,国产精品视频久久

干貨分享建議收藏:Jenkins集成GitLab

Jenkins免密拉取GitLab項(xiàng)目

1.在Jenkins上為GitLab創(chuàng)建一個(gè)專有的拉取代碼的賬號(hào) Jenkins需要構(gòu)建哪些項(xiàng)目就在GitLab給予賬號(hào)相應(yīng)權(quán)限 我這里已經(jīng)創(chuàng)建過(guò)Jenkins用戶,下面用它登錄后添加SSH-KEY

干貨分享建議收藏:Jenkins集成GitLab

2.在Jenkins服務(wù)器上生成ssh-key


[root@jenkins ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:IUQIuu0SAdSbZvENbIjFYTrUrnuqKGBmZtwPj6lvz60 root@jenkins
The key's randomart image is:
+---[RSA 2048]----+
|ooB=+oo          |
|ooo*.=           |
|oo. * + .        |
| +.* . o .       |
|+ *     S        |
|.@ o             |
|O o *            |
|oo =.o.          |
|=o*..E..         |
+----[SHA256]-----+

查看公鑰

[root@jenkins ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7ckQQf4N93Rjf0ts3Lk4siL6FZmZiBiB+ouwTgw9kKof2NeJTguf0aNfDsgSEet4+bJ53ZKztsFZE/C+sqk7grqeLeYDFBWgdZBz1dmCYT51tRFmZPDEDclOIMc2tz0G50g6DFA1dvIfkzeVbKjBNN0o80FSAwAzrtjMrkyaDcrOmYekiSPM8JYJTTcFLCzIBXz7SXOmKH5vyoAIVpdcwnIhkHNLKfD0MdzGb7Kz/pKMnLubodcxyNir6fqw76qwMe1DE0NtQzpaCrTYhVnAizVqCDek0GMZjTG1vWYNn6a8G7omV3Gde1XjcmjAj6ftVQiVLBRJaIGKI4R/B//nd root@jenkins

將Jenkins的公鑰填入GitLab賬號(hào)中

干貨分享建議收藏:Jenkins集成GitLab

3.測(cè)試SSH-KEY 到j(luò)enkins服務(wù)器上拉取項(xiàng)目來(lái)測(cè)試ssh-key免密是否生效

[root@jenkins ~]# yum install git -y
[root@jenkins ~]# git clone git@106.14.10.124:dev01/sample.git
正克隆到 'sample'...
The authenticity of host '106.14.10.124 (106.14.10.124)' can't be established.
ECDSA key fingerprint is SHA256:bO22/HlgAAGXi9CXTxDE6wvNCUcTs2OajL9PinZMN/0.
ECDSA key fingerprint is MD5:ec:4f:14:0a:b6:72:cf:6e:da:5b:fa:5b:be:b9:2f:db.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '106.14.10.124' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
接收對(duì)象中: 100% (6/6), done.

如上,ssh-key已生效

配置jenkins自動(dòng)拉取代碼

1.jenkins 服務(wù)器添加證書(shū) 系統(tǒng)配置——》Manage Credentials

干貨分享建議收藏:Jenkins集成GitLab

系統(tǒng)配置——》Manage Credentials——》Jenkins——》全局憑證——》添加憑證

干貨分享建議收藏:Jenkins集成GitLab

這樣的話Jenkins服務(wù)器拉取GitLab的代碼就不需要再進(jìn)行認(rèn)證了。

Jenkins安裝GitLab插件

1.安裝插件 插件名稱:

?GitLab

?Gitlab Hook

?Gitlab Authentication

?GitLab Logo

干貨分享建議收藏:Jenkins集成GitLab

安裝完成后重啟Jenkins

GitLab為Jenkins生成Token

1.我們使用Jenkins用戶登錄GitLab 然后使用Jenkins用戶創(chuàng)建Token

干貨分享建議收藏:Jenkins集成GitLab

2.復(fù)制創(chuàng)建的Token

干貨分享建議收藏:Jenkins集成GitLab

3.打開(kāi)Jenkins 系統(tǒng)管理——》系統(tǒng)配置

干貨分享建議收藏:Jenkins集成GitLab

輸入以下相關(guān)內(nèi)容

干貨分享建議收藏:Jenkins集成GitLab

選擇憑證,測(cè)試后保存

干貨分享建議收藏:Jenkins集成GitLab

4.查看憑證 現(xiàn)在有以下兩種方式與GitLab進(jìn)行認(rèn)證

?通過(guò)GitLab上Jenkins用戶的密鑰(GitLab綁定Jenkins用戶的公鑰,Jenkins綁定GitLab上Jenkins用戶的私鑰)、

?通過(guò)GitLab上Jenkins用戶的API Token綁定到Jenkins上的GitLab authentication插件上進(jìn)行連接。
Jenkins構(gòu)建流水線
創(chuàng)建Project 新建任務(wù)——》流水線

干貨分享建議收藏:Jenkins集成GitLab

2.選擇流水線語(yǔ)法

干貨分享建議收藏:Jenkins集成GitLab

3.生成流水線腳本

干貨分享建議收藏:Jenkins集成GitLab

復(fù)制生成的git腳本

4.編寫(xiě)Pipline腳本 我這里腳本如下

node {
    stage('拉取代碼'){
        git credentialsId: 'b907af22-5a74-4eee-aa5f-a822c764279c', url: 'git@172.19.95.139:dev01/sample.git'
        echo "Code Pull"
    }
    stage('代碼掃描'){
        echo "Code Scanning"
    }
    stage('代碼構(gòu)建'){
        echo "Code Build"
    }
    stage('是否部署'){
        input '是否部署'
    }    
    stage('開(kāi)始部署'){
        sh '/opt/jenkins/sample/sample_release.sh'
    }
}

將以上腳本寫(xiě)流水線中

干貨分享建議收藏:Jenkins集成GitLab

上面腳本最后執(zhí)行了/opt/jenkins/sample/sample_release.sh腳本,我們到執(zhí)行任務(wù)的Jenkins服務(wù)器上去編寫(xiě)這個(gè)部署腳本。腳本如下:jenkins服務(wù)器將/usr/local/src/sample.zip文件拷貝到了172.19.182.107上

[root@jenkins /]# cat /opt/jenkins/sample/sample_release.sh
#!/usr/bin/env bash

scp /usr/local/src/sample.zip root@172.19.182.107:/usr/local/

這里我們需要先讓Jenkins服務(wù)器與172.19.182.107做免密登錄,將Jenkins的公鑰拷貝到172.19.182.107服務(wù)中的/root/.ssh/authorized_keys文件中

#Jenkins的公鑰(這里為root的公鑰,Jenkins進(jìn)程就需要用root用戶運(yùn)行)
[root@jenkins /]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7ckQQf4N93Rjf0ts3Lk4siL6FZmZiBiB+ouwTgw9kKof2NeJTguf0aNfDsgSEet4+bJ53ZKztsFZE/C+sqk7grqeLeYDFBWgdZBz1dmCYT51tRFmZPDEDclOIMc2tz0G50g6DFA1dvIfkzeVbKjBNN0o80FSAwAzrtjMrkyaDcrOmYekiSPM8JYJTTcFLCzIBXz7SXOmKH5vyoAIVpdcwnIhkHNLKfD0MdzGb7Kz/pKMnLubodcxyNir6fqw76qwMe1DE0NtQzpaCrTYhVnAizVqCDek0GMZjTG1vWYNn6a8G7omV3Gde1XjcmjAj6ftVQiVLBRJaIGKI4R/B//nd root@jenkins

#172.19.182.107服務(wù)器的authorized_keys文件
cat /root/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7ckQQf4N93Rjf0ts3Lk4siL6FZmZiBiB+ouwTgw9kKof2NeJTguf0aNfDsgSEet4+bJ53ZKztsFZE/C+sqk7grqeLeYDFBWgdZBz1dmCYT51tRFmZPDEDclOIMc2tz0G50g6DFA1dvIfkzeVbKjBNN0o80FSAwAzrtjMrkyaDcrOmYekiSPM8JYJTTcFLCzIBXz7SXOmKH5vyoAIVpdcwnIhkHNLKfD0MdzGb7Kz/pKMnLubodcxyNir6fqw76qwMe1DE0NtQzpaCrTYhVnAizVqCDek0GMZjTG1vWYNn6a8G7omV3Gde1XjcmjAj6ftVQiVLBRJaIGKI4R/B//nd root@jenkins

#測(cè)試免密登錄
[root@jenkins /]# ssh root@172.19.182.107
Last login: Tue Jun 30 20:26:12 2020 from 172.19.206.72

Welcome to Alibaba Cloud Elastic Compute Service !

Jenkins執(zhí)行任務(wù)

1.進(jìn)入到任務(wù)中

干貨分享建議收藏:Jenkins集成GitLab

2.點(diǎn)擊立即構(gòu)建

干貨分享建議收藏:Jenkins集成GitLab

3.是否部署

干貨分享建議收藏:Jenkins集成GitLab
干貨分享建議收藏:Jenkins集成GitLab
今天的分享到這里就結(jié)束了,希望大家持續(xù)關(guān)注馬哥教育官網(wǎng),每天都會(huì)有大量?jī)?yōu)質(zhì)內(nèi)容與大家分享!
文章來(lái)源于網(wǎng)絡(luò),侵刪!

相關(guān)新聞

歷經(jīng)多年發(fā)展,已成為國(guó)內(nèi)好評(píng)如潮的Linux云計(jì)算運(yùn)維、SRE、Devops、網(wǎng)絡(luò)安全、云原生、Go、Python開(kāi)發(fā)專業(yè)人才培訓(xùn)機(jī)構(gòu)!

    1. 主站蜘蛛池模板: 平遥县| 静安区| 海盐县| 靖安县| 璧山县| 青川县| 龙泉市| 遵义市| 罗甸县| 龙里县| 简阳市| 新竹市| 晴隆县| 庄河市| 晋城| 嵩明县| 古丈县| 盐津县| 汽车| 龙川县| 顺义区| 麻城市| 河北区| 溧水县| 左贡县| 榆林市| 织金县| 荣昌县| 迁西县| 历史| 治多县| 丹巴县| 永康市| 奇台县| 江北区| 太谷县| 宝山区| 怀宁县| 云和县| 泰安市| 犍为县|