当前位置: 首页 > news >正文

pipeline agent分布式构建

开启 agent

root@jenkins:~/learning-jenkins-cicd/07-jenkins-agents# docker-compose -f docker-compose-inbound-agent.yml up -d

Jenkins配置添加

pipeline { agent { label 'docker-jnlp-agent' }parameters {booleanParam(name:'pushImage', defaultValue: 'true', description: 'Push Image to Harbor?')}    tools {maven 'Maven-3.8.8'}triggers {GenericTrigger(genericVariables: [[key: 'ref', value: '$.ref']],token: 'fClZ0e/kTcqL2ARh7YqxW/3ndOCZA2SqfKnRTLat',causeString: 'Triggered on $ref',printContributedVariables: true,printPostContent: true)}   environment {codeRepo="http://192.168.1.50/root/spring-boot-helloWorld.git"harborServer='harbor.luohw.net'projectName='spring-boot-helloworld'imageUrl="${harborServer}/ikubernetes/${projectName}"imageTag='latest'}stages {stage('Source') {steps {git branch: 'main', credentialsId: 'gitlab-root-credential', url: "${codeRepo}"}}stage('Build') {steps {sh 'mvn -B -DskipTests clean package'}}stage('Test') {steps {sh 'mvn test'}}stage("SonarQube Analysis") {steps {withSonarQubeEnv('SonaQube-Server') {sh 'mvn sonar:sonar'}}}stage("Quality Gate") {steps {timeout(time: 30, unit: 'MINUTES') {waitForQualityGate abortPipeline: true}}}        stage('Build Docker Image') {agent { label 'master' }steps {sh 'docker image build . -t "${imageUrl}:${imageTag}"'// input(message: '镜像已经构建完成,是否要推送?')}           }stage('Push Docker Image') {agent { label 'master' }when {expression { params.pushImage }}steps {withCredentials([usernamePassword(credentialsId: 'harbor-user-credential', passwordVariable: 'harborUserPassword', usernameVariable: 'harborUserName')]) {sh "docker login -u ${env.harborUserName} -p ${env.harborUserPassword} ${harborServer}"sh "docker image push ${imageUrl}:${imageTag}"}}   }        }post{success{qyWechatNotification failNotify: true, webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5530d220-0983-490e-ada5-a74fa66570c8'}failure{qyWechatNotification failNotify: true, webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=5530d220-0983-490e-ada5-a74fa66570c8'}} 
}

192.168.1.51:50000

示例:基于Kubernetes完成构建

添加pod模版
kube-agent222

maven:3.8.6-eclipse-temurin-17-alpine

挂载路径
/root/.m2

配置pod模版
在这里插入图片描述

编辑流水线

pipeline {agent {kubernetes {inheritFrom 'kube-maven'}}parameters {booleanParam(name:'pushImage', defaultValue: 'true', description: 'Push Image to Harbor?')}    tools {maven 'Maven-3.8.8'}triggers {GenericTrigger(genericVariables: [[key: 'ref', value: '$.ref']],token: 'fClZ0e/kTcqL2ARh7YqxW/3ndOCZA2SqfKnRTLat',causeString: 'Triggered on $ref',printContributedVariables: true,printPostContent: true)}   environment {codeRepo="http://192.168.1.50/root/spring-boot-helloWorld.git"harborServer='hub.magedu.com'projectName='spring-boot-helloworld'imageUrl="${harborServer}/ikubernetes/${projectName}"imageTag='latest'}stages {stage('Source') {steps {git branch: 'main', credentialsId: 'gitlab-root-credential', url: "${codeRepo}"}}stage('Build') {steps {container('maven') {sh 'mvn -B -DskipTests clean package'}}}stage('Test') {steps {container('maven') {sh 'mvn test'}}}stage("SonarQube Analysis") {steps {container('maven') {                withSonarQubeEnv('SonarQube-Server') {sh 'mvn sonar:sonar'}}}}stage("Quality Gate") {steps {timeout(time: 30, unit: 'MINUTES') {waitForQualityGate abortPipeline: true}}}               }post{success{qyWechatNotification failNotify: true, webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c79e3215-d39f-44a7-a760-fa0ab63ca46b'}failure{qyWechatNotification failNotify: true, webhookUrl: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c79e3215-d39f-44a7-a760-fa0ab63ca46b'}}   
}

在这里插入图片描述

maven-and-docker

添加pod模版
在这里插入图片描述

在这里插入图片描述

http://www.lryc.cn/news/233525.html

相关文章:

  • MySQL(17):触发器
  • 挖掘PostgreSQL事务的“中间态”----更加严谨的数据一致性?
  • 多种方法实现conda环境迁移
  • C++ string类(一)
  • 系统时间和JVM的Date时间不一致问题解决
  • 23111701[含文档+PPT+源码等]计算机毕业设计javaweb点餐系统全套餐饮就餐订餐餐厅
  • RabbitMQ 部署及配置详解(集群部署)
  • 基于蝠鲼觅食算法优化概率神经网络PNN的分类预测 - 附代码
  • 「分享学习」SpringCloudAlibaba高并发仿斗鱼直播平台实战完结
  • Vue|props配置
  • 使用Microsoft Dynamics AX 2012 - 2. 入门:导航和常规选项
  • 【代码随想录】算法训练计划21、22
  • java实现钉钉机器人消息推送
  • C语言之break continue详解
  • mysql group by 执行原理及千万级别count 查询优化
  • Linux的几个常用基本指令
  • mac中安装Homebrew
  • Vue23的计算属性(computed)
  • vue3中祖孙组件之间的通信provide和inject
  • 月影下的时光机:Python中的日期、时间、农历、节气和时区探秘
  • 【Bazel】Bazel 学习笔记
  • 2023年“华为杯”第二十届中国研究生数学建模成绩数据分析(末尾有吃席群)
  • Linux文件和文件夹命令详解
  • MIKE水动力笔记20_由dfs2网格文件提取dfs1断面序列文件
  • 微服务nacos实战入门
  • PyCharm 远程连接服务器并使用服务器的 Jupyter 环境
  • HBase中的数据表是如何用CHAT进行分区的?
  • rabbitMQ的direct模式的生产者与消费者使用案例
  • 分布式应用服务拆分
  • matplotlib 绘制双纵坐标轴图像