|NO.Z.00038|——————————|CloudNative|——|CI/CD&Jenkins_pipeline操作.V12|——|Jenkins_pipeline插件|
一、Jenkins pipeline插件安装
### --- Jenkins pipeline概述
### --- 安装jenkins pipeline插件
~~~ ——>在对 jenkins 进行初始化安装时,默认已经安装了 jenkins 的相关插件,如下图所示:


### --- Jenkins pipeline配置流水线
~~~ # 新建任务
~~~ ——>编写 pipeline 脚本
~~~ ——>可以借助流水线语法去做。
~~~ # ——>test 流水线脚本:
node {
def mvnHome
stage('git checkout') { #for display purposes
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@10.10.10.13:/home/git/repos/app.git']]])
}
stage('maven Build') {
echo "maven build........."
}
stage('deploy') {
echo "deploy..........."
}
stage('test') {
echo "test..........."
}
}


三、构建测试
### --- 构建测试
~~~ ——>可以去服务器上验证一下(git checkout)刚才拉取下来的代码:
[root@jenkins ~]# ll /var/lib/jenkins/workspace/pipeline-test/
total 0
-rw-r--r-- 1 root root 0 Mar 30 16:59 index1.html
-rw-r--r-- 1 root root 0 Mar 30 16:59 index.html
~~~ # ——>补充:
~~~ ——>可以从代码版本管理仓库中读取 pipeline 脚本(相当于将 pipeline 脚本放在仓库中)可以选择git。
~~~ ——>首先需要将 pipeline 脚本提交到我们新建的 git仓库中(步骤再此忽略。)

四、jenkins 项目中需要进行如下配置:
### --- jenkins 项目中需要进行如下配置:
~~~ ——>其中脚本路径的配置,一定要和版本仓库中的路径相一致。
~~~ ——>之后如果要更改步骤,不需要再更改 jenkins 的步骤,直接更改文件即可。
~~~ # ——>补充:
~~~ ——>此外之前的测试一直是在 master上构建的,我们还可以通过在 jenkinsfile 中指定节点在相应节点去构建具体在 jenkinsfile 的 node 后进行指定:
~~~ ——>如下图所示:
[root@jenkins ~]# vim /root/jenkinsfile/item-a/jenkinsfile
node ("slave01-10.10.10.11"){
def mvnHome
stage('git checkout') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'git@10.10.10.13:/home/git/repos/app.git']]])
}
stage('maven Build') {
echo "maven build........."
}
stage('deploy') {
echo "deploy..........."
}
stage('test') {
echo "test..........."
}
}
~~~ ——>格式为:node ("节点名称")
~~~ ——>**具体配置详解请参考** https://jenkins.io/doc/book/pipeline/


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
分类:
cdv015-jenkins2
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」