Jenkins Pipeline 流水线 - 拉代码(SVN) + Maven 编译打包

jenkins,pipeline,流水线,代码,svn,maven,编译,打包 · 浏览次数 : 1861

小编点评

## Jenkins Pipeline 流水线步骤拉取SVN代码 ```groovy pipeline { agent any tools { maven 'Maven36' // 添加 Maven 工具 } stages { stage('拉取代码') { steps { checkout([ $class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: '凭证ID,如果没设,默认会给 GUID', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'SVN 地址']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater'] ]) echo '拉取成功' } } stage('执行构建') { steps { bat 'mvn --version' // 查看 Maven 版本 bat 'mvn clean package -Dmaven.test.skip=true' // 执行 Maven clean 和 package 命令 echo '构建完成' } } } } ``` **说明:** * 此 Jenkins Pipeline 包含拉取 SVN 代码、执行 Maven 构建和发布至阿里云仓库的步骤。 * 每个 stage 中包含了相应的步骤,其中包含 `checkout`、`echo`、`bat` 等执行命令。 * 使用 `$class: 'SubversionSCM'` 取得 Subversion Scm 的对象,并根据配置的用户名和密码进行登录。 * 使用 `$class: 'UpdateUpdater'` 调整 Jenkins 工作空间的更新策略,并根据配置的版本控制系统进行代码更新。 * 使用 `cancelProcessOnExternalsFail: true` 和 `ignoreExternalsOption: true` 设置如果网络连接失败或远程仓库无法访问的情况下,是否取消流程。 * 使用 `credentialsId` 的形式指定凭证 ID,您可以根据实际情况进行调整。

正文

Jenkins Pipeline 流水线

步骤

拉取SVN代码 -> Maven 构建 -> Docker 编译 -> 发布至阿里云仓库 -> K8S 更新

Jenkins插件安装

  • Localization: Chinese (Simplified)
  • Subversion 【2.16.0】 --从SVN中获取代码
  • Maven Integration 【3.20】 -- 编译项目
  • Docker plugin 【1.2.10】 -- 用于节点管事中的 Docker 维护
  • docker-build-step 【2.8】 -- 用于 Post Steps 的时候,选择 Build/Publish Docker Image
  • SSH 【6.1】-- 用于集成 K8S,远程执行K8S服务器上的命令

拉取SVN代码

流水线语法生成
image
选择 Subversion 生成流水线脚本
image
image
image
image
构建
image
image

编译构建代码

  1. 找到 Maven 的名字
    image
    image
    image
    image
    image
Cannot run program "nohup" (in directory "D:\ProgramData\Jenkins\.jenkins\workspace\PipelineDemo"): 
CreateProcess error=2, 系统找不到指定的文件。

解决方法:因为我这边是 Windows 上装的 Jenkins 所以,sh 要换成 bat
image
image
修改打包命令
image
image
image

pipeline {
    agent any

    tools {
        maven 'Maven36'  //添加 Maven 工具
    }
    stages {
        stage('拉取代码') {
            steps {
                checkout([$class: 'SubversionSCM', additionalCredentials: [], excludedCommitMessages: '', excludedRegions: '', excludedRevprop: '', excludedUsers: '', filterChangelog: false, ignoreDirPropChanges: false, includedRegions: '', locations: [[cancelProcessOnExternalsFail: true, credentialsId: '凭证ID,如果没设,默认会给 GUID', depthOption: 'infinity', ignoreExternalsOption: true, local: '.', remote: 'SVN 地址']], quietOperation: true, workspaceUpdater: [$class: 'UpdateUpdater']])  //该脚本由流水线语法自动生成
                echo '拉取成功'
            }
        }

        stage('执行构建') {
            steps {
                //bat 'mvn --version'
                bat 'mvn clean package -Dmaven.test.skip=true'
                echo '构建完成'
            }
        }
    }
}

与Jenkins Pipeline 流水线 - 拉代码(SVN) + Maven 编译打包相似的内容:

Jenkins Pipeline 流水线 - 拉代码(SVN) + Maven 编译打包

Jenkins Pipeline 流水线 步骤 拉取SVN代码 -> Maven 构建 -> Docker 编译 -> 发布至阿里云仓库 -> K8S 更新 Jenkins插件安装 Localization: Chinese (Simplified) Subversion 【2.16.0】 --从S

Jenkins Pipeline 流水线 - 完整构建 Pipeline Script 脚本

Docker Jenkins 安装配置 Windows 2016 安装 Jenkins 前置条件可参考 Jenkins Pipeline 流水线 - 拉代码(SVN) + Maven 编译打包 Jenkins Pipeline 流水线 - 添加节点 使用代理 Jenkins Pipeline 流水线

Jenkins Pipeline 流水线 - 声明式 Demo

Jenkins Pipeline 流水线 流水线既能作为任务的本身,也能作为 Jenkinsfile 使用流水线可以让我们的任务从UI手动操作,转换为代码化,像dockerfile 一样。从shell 命令到配置文件,更适合大型项目,可以让团队其他开发者同时参与进来, 完整语法 tools:添加工具

Jenkins Pipeline 流水线 - 添加节点 使用代理

Jenkins 安装在 Windows 上 Docker 在Linux 上 流程 将 Docker 在 Jenkins 节点中维护 Pipeline 中指定某些阶段使用哪个节点 添加节点 Checking Java version in the PATH openjdk version "1.8.0

Jenkins Pipeline 流水线 - withCredentials 使用

添加凭证 Pipeline script pipeline { agent any stages { stage('withCredentials 使用凭证') { steps { withCredentials([usernamePassword(credentialsId: 'DockerSer

Jenkins Pipeline 流水线 - 上传文件 Publish over SSH 执行命令

Jenkins Pipeline 流水线 - 上传文件 Publish over SSH 执行命令 Jenkins插件安装 Publish over SSH 系统配置 生成代码 sshPublisher: Send build artifacts over SSH 需要在 生成 sshPublish

Jenkins Pipeline 流水线 - 上传文件 Publish over SSH + Docker 编译 + 上传到阿里仓库

Jenkins Pipeline 流水线 Publish over SSH 将jar上传到远程 Docker 服务器、执行编译命令生成镜像、将镜像上传到阿里仓库 Publish over SSH Jar包上传、编译、上传 生成上传 jar 包脚本配置 生成上传 Dockerfile 脚本配置 注意在

Jenkins Pipeline 流水线 - 使用代理节点,Remote SSH 对 K8S 进行升级

Jenkins Pipeline 流水线 - K8S kubectl 升级 使用代理节点 Remote SSH 远程执行命令进行升级 Remote SSH 方式 安装插件 SSH Pipeline Steps Pipeline SSH 脚本 credentialsId: 'K8SMaster' pi

Jenkins Pipeline 流水线 - Parameters 参数化构建

可以通过参数的方式,指定构建的版本 有两种方式 界面添加 Pipeline Script 脚本配置 (需要Build 一次,然后生效,不知道有没有其它办法) General 界面添加 Pipeline Script Declarative Directive Generator pipeline {

Jenkins 多分支流水线(SVN)

实际应用过程中,一般多分支流水线的方式用得比较多一些, master 对应 生成环境 develop 对应 测试环境, 将不同分支的代码构建到不同的环境中 添加 Jenkinsfile 文件 Jenkinsfile 内容见:Jenkins Pipeline 流水线 - 完整构建 Pipeline S