“Pipeline”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
 
(未显示同一用户的47个中间版本)
第1行: 第1行:
 
=Jenkins Pipeline 简介=
 
=Jenkins Pipeline 简介=
 +
https://www.jenkins.io/zh/doc/book/pipeline/
 
Jenkins pipeline 是 Jenkins 2.0 的精髓,,是帮助 Jenkins 实现 CI 到 CD 转变的重要角色。
 
Jenkins pipeline 是 Jenkins 2.0 的精髓,,是帮助 Jenkins 实现 CI 到 CD 转变的重要角色。
 +
 +
注意  现在程序员的代码一般在pipeline的step里面 而不是以前的在代码管理了啦, 代码管理那现在是管理jenkinsfile etc
  
 
简单来说,就是一套运行于 Jenkins 上的工作流框架,将原本独立运行于单个或者多个节点的任务连接起来,实现单个任务难以完成的复杂发布流程。
 
简单来说,就是一套运行于 Jenkins 上的工作流框架,将原本独立运行于单个或者多个节点的任务连接起来,实现单个任务难以完成的复杂发布流程。
第97行: 第100行:
 
</pre>
 
</pre>
  
 +
=git timeout=
 +
<pre>
 +
#有时候会timout 于是 你懂的 配置一下  在pepeline脚本中的extensions(扩展插件)中添加设置timeout时间为30min,默认为10min,即可解决
 +
pipeline {
 +
    agent any
 +
 +
    stages {
 +
        stage('Build') {
 +
            steps {
 +
                // Get some code from a Git repository
 +
                checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [[$class:'CheckoutOption',timeout:30]], userRemoteConfigs: [[credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: '[email protected]:php/project.git']]])
 +
                //checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [], userRemoteConfigs: [[credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: '[email protected]:php/project.git']]])
 +
 +
 +
 +
#my eg  现在这个问题是有个项目的代码非常大的  程序哥说平时都拉半个小时的 于是只能配置为 12000,不然老是 fail
 +
steps {
 +
                // Get some code from a Git repository  git clone timeout  troubleshooting
 +
                sh "git config --global http.postBuffer 1048576000"
 +
                sh "git config --list"
 +
                //git branch: 'beta', credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: '[email protected]:php/product-server.git'
 +
                checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [[$class:'CheckoutOption',timeout:3000],[$class: 'CloneOption', timeout: 12000]], userRemoteConfigs: [[credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: '[email protected]:php/product-server.git']]])
 +
 +
 +
#eg
 +
checkout([
 +
      $class: 'GitSCM', branches: [[name: "${branch}"]],
 +
      doGenerateSubmoduleConfigurations: false,extensions: [[$class:'CheckoutOption',timeout:30],[$class:'CloneOption',depth:0,noTags:false,reference:'',shallow:false,timeout:30]], submoduleCfg: [],
 +
      userRemoteConfigs: [[credentialsId: 'xxxxx', url: "${project_url}"]]
 +
 +
checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [[$class:'CheckoutOption',timeout:3000],[$class: 'CloneOption', timeout: 12000]], userRemoteConfigs: [[credentials
 +
 +
 +
脚本式pipeline
 +
 +
node {
 +
 +
stage('clone') { // for display purposes
 +
    // Get some code from a GitHub repository
 +
    checkout([$class: 'GitSCM',
 +
        branches: [[name: '*/master']],
 +
        extensions: [[$class: 'CloneOption', timeout: 120]],
 +
        gitTool: 'Default',
 +
        userRemoteConfigs: [[url: 'https://github.com/LimeSurvey/LimeSurvey.git']]
 +
    ])
 +
}
 +
 +
stage('zip'){
 +
    zip zipFile: './publish.zip',
 +
        archive: true
 +
}}
 +
 +
 +
</pre>
 +
[https://blog.csdn.net/liliwang90/article/details/108855725  Pipeline设置默认超时时间,并指定变量时自动更改超时时间]
 +
 +
[https://blog.csdn.net/weixin_43619065/article/details/109235245  git clone克隆过早结束解决方法(git clone early EOF error solution)]
 +
 +
[https://blog.csdn.net/m0_49337600/article/details/111404767  git 解决 fatal- 过早的文件结束符(EOF) fatal- index-pack failed]
 +
 +
[https://stackoverflow.com/questions/49699379/configure-git-timeout-on-jenkins-pipeline-with-classic-ui Configure git timeout on Jenkins pipeline with Classic UI]
 +
 +
=常用例子=
 +
==eg==
 +
<pre>
 +
 +
举个栗子,保留历史构建次数的。将下面的块结构体放入 pipeline 中即可。
 +
 +
// 设置保留构建次数
 +
options {
 +
    buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
 +
}
 +
 +
</pre>
 +
== 清理空间==
 +
https://plugins.jenkins.io/ws-cleanup/
 +
==Jenkins管道如何更改到另一个文件夹==
 +
<pre>
 +
pipeline {
 +
    agent any
 +
 +
    stages {
 +
        stage('Build') {
 +
            steps {
 +
                // Get some code from a Git repository
 +
                checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [[$class:'CheckoutOption',timeout:30]], userRemoteConfigs: [[credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: 'git@git./server.git']]])
 +
 +
                dir("${env.WORKSPACE}/www/l.com"){
 +
                    //sh "composer install"
 +
                    sh "rm -rf ${env.WORKSPACE}/www/l.com@tmp"
 +
                    sh " echo git code ok "
 +
                }
 +
 +
 +
                sh " rsync  -aqz --progress --exclude-from=/backup/upline/exclude  ${env.WORKSPACE}/www/  [email protected]:/data/2"
 +
                sh " ssh [email protected]  chown -R www.www  /data/2"
 +
 +
            }
 +
 +
</pre>
 +
 +
[https://stackoverflow.com/questions/52372589/jenkins-pipeline-how-to-change-to-another-folder Jenkins pipeline how to change to another folder]
 +
 +
 +
[https://www.codenong.com/52372589/ 关于groovy:Jenkins管道如何更改到另一个文件夹]
 +
==pipeline 多行执行shell 命令  ==
 +
<pre>
 +
 +
#但是今天独立拿出来 rsync 居然不成功 怪 里面有变量  要用""" """
 +
                dir("${env.WORKSPACE}/www/client.cfb.com"){
 +
                    sh '''cnpm install
 +
                      cnpm install core-js@2
 +
                      npm run deploy:beta
 +
                   
 +
                    '''
 +
                   
 +
 +
                }
 +
 +
 +
 +
 +
                sh """
 +
                    rsync  -aqz --progress --exclude-from=/backup/upline/exclude ${env.WORKSPACE}/www/im.com/deploy  [email protected]:/data/
 +
                    ssh [email protected]  chown -R apache.apache  /data/nginx/proxy/sscf-crm-im-proxy
 +
                       
 +
 +
 +
                """
 +
 +
 +
 +
 +
 +
 +
 +
</pre>
 +
[https://blog.51cto.com/u_11101184/3135922 Jenkins Pipeline」- 执行 Shell 命令]
 +
 +
https://www.jenkins.io/zh/doc/pipeline/tour/running-multiple-steps/
 +
 +
https://stackoverflow.com/questions/44330148/run-bash-command-on-jenkins-pipeline/
 +
 +
[https://www.it-swarm.cn/zh/jenkins/jenkins%E7%AE%A1%E9%81%93%EF%BC%9A%E5%B8%A6%E7%AE%A1%E9%81%93%E7%9A%84%E5%A4%9A%E8%A1%8Cshell%E5%91%BD%E4%BB%A4/830651025/ jenkins管道:带管道的多行Shell命令]
 +
 +
=IDE vscode=
 +
添加 Jenkins Pipeline Linter Connector
 
=进阶advance=
 
=进阶advance=
 +
 +
[https://www.jianshu.com/p/3d5a065ffec9 Docker+Jenkins+Pipeline实现持续集成-模板]
  
 
[https://www.jenkins.io/zh/doc/book/pipeline/getting-started/ .jenkins.io/zh/doc/book  流水线入门]
 
[https://www.jenkins.io/zh/doc/book/pipeline/getting-started/ .jenkins.io/zh/doc/book  流水线入门]
第145行: 第297行:
 
[https://blog.csdn.net/weixin_43304804/article/details/85272386  Pipeline流水线及分布式流水线发布PHP项目及JAVA项目]
 
[https://blog.csdn.net/weixin_43304804/article/details/85272386  Pipeline流水线及分布式流水线发布PHP项目及JAVA项目]
  
 
+
[https://www.jenkins.io/zh/doc/tutorials/build-a-java-app-with-maven/ jenkins.io使用Maven构建Java应用程序 ]
  
 
[https://blog.51cto.com/u_13760351/2527263  Jenkins--pipline 流水线部署Java后端项目]
 
[https://blog.51cto.com/u_13760351/2527263  Jenkins--pipline 流水线部署Java后端项目]
第207行: 第359行:
  
 
<gallery>Jul012021j1.png</gallery>
 
<gallery>Jul012021j1.png</gallery>
 +
 +
[https://juejin.cn/post/6844903955600769031 最优雅的Docker+Jenkins pipeline部署Spring boot项目 ]
  
 
===新建Pipeline 项目===
 
===新建Pipeline 项目===
第215行: 第369行:
  
 
<pre>
 
<pre>
 +
 +
包目录
 +
van@myxps:~$ ls data/jenkins/workspace/01_Eureka/eureka-server/target/eureka-server-1.0.0.jar
 +
data/jenkins/workspace/01_Eureka/eureka-server/target/eureka-server-1.0.0.jar
 +
 +
 
tree .
 
tree .
 
.
 
.
第279行: 第439行:
  
 
脚本路径  jenkins_files/01_eureka
 
脚本路径  jenkins_files/01_eureka
 +
 +
 +
==== 最简单的pipeline maven java====
 +
 +
[https://blog.51cto.com/u_15127511/2657839 Jenkinsfile入门:Pipeline使用Maven构建java项目]
 +
<pre>
 +
源码及Jenkinsfile
 +
https://github.com/evan886/pipeline-maven-eg
 +
 +
 +
分支 main  注意了
 +
 +
checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: '55c4819e-ac29-47c8-97d0-528252de42ef', url: 'http://mygitlab.com/root/pipeline-maven-eg']]])
 +
 +
 +
 +
 +
就是作测试居然遇到个坑 哈哈 on my kali
 +
[ERROR] COMPILATION ERROR :
 +
 +
[INFO] -------------------------------------------------------------
 +
 +
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
 +
 +
 +
 +
maven settings.xml
 +
 +
 +
居然用jdk11 可以去编译pom.xml 1.8的
 +
 +
jenkins 可能要的配置
 +
manage jenkins -->configure system -->全局属性--  勾上 environment variables 
 +
 +
键 JAVA_HOME 
 +
值 /usr/lib/jvm/java-11-openjdk-amd64
 +
 +
 +
 +
 +
cat  /etc/profile
 +
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
 +
 +
 +
jenkins/workspace/pipeline-maven-eg/target# java  -jar  pipeline-demo-0.0.1-SNAPSHOT.jar
 +
 +
http://localhost:40080/
 +
 +
 +
 +
 +
</pre>
  
 
====see also springboot ====
 
====see also springboot ====
 +
[https://blog.csdn.net/weixin_39947101/article/details/107448285 生成流水脚本 Jenkins构建Maven项目 【Pipeline流水线方式构建]
 +
 +
 
[https://www.cnblogs.com/SimpleWu/p/13262966.html  Jenkins Pipeline 部署 SpringBoot 应用 ]
 
[https://www.cnblogs.com/SimpleWu/p/13262966.html  Jenkins Pipeline 部署 SpringBoot 应用 ]
  
 
[https://juejin.cn/post/6844903955600769031 最优雅的Docker+Jenkins pipeline部署Spring boot项目 ]
 
[https://juejin.cn/post/6844903955600769031 最优雅的Docker+Jenkins pipeline部署Spring boot项目 ]
 +
 +
[https://www.cnblogs.com/xiaodai12138/p/9996995.html  Jenkins Pipeline+Maven+Gitlab持续集成构建 ]
  
 
=== Pipeline流水线+ Docker(docker java应用)实现自动化CI/CD发布Java项目===
 
=== Pipeline流水线+ Docker(docker java应用)实现自动化CI/CD发布Java项目===
第291行: 第508行:
  
 
[https://juejin.cn/post/6844903955634323469 最优雅的Docker+Jenkins pipeline部署vue项目,前端项目都可参考 ]
 
[https://juejin.cn/post/6844903955634323469 最优雅的Docker+Jenkins pipeline部署vue项目,前端项目都可参考 ]
 +
 +
[https://blog.csdn.net/cckevincyh/article/details/88625597  使用Docker+Jenkins+Pipeline将Vue项目部署到Nginx服务器]
 +
=== war tomcat===
 +
[https://blog.51cto.com/hld1992/2385108 Pipeline自动化构建发布Java tomcat项目 声明式]
 +
=== pipeline php ===
 +
 +
[https://www.cnblogs.com/cyleon/p/11913088.html  Jenkins + pipeline + Git + PHP (九) 这个对的]
 +
 +
[https://yuerblog.cc/2018/12/06/k8s-jenkins-pipeline-php-docker-harbor/ k8s系列 – jenkins pipeline打包php docker镜像保存harbor仓库]
 +
 +
[https://blog.csdn.net/weixin_43304804/article/details/85272386  Pipeline流水线及分布式流水线发布PHP项目及JAVA项目]
 +
 +
[https://blog.csdn.net/weixin_30265171/article/details/98367981#t7  项目案例之Pipeline流水线及流水线发布PHP项目(二)]
 +
 +
[https://www.cnblogs.com/linyaonie/p/11238321.html Jenkins的Pipeline流水线]
 +
 +
[https://www.cnblogs.com/ywb123/p/11222980.html 项目案例之Pipeline流水线及流水线发布PHP项目]
  
 
=docker=
 
=docker=
  
 
[https://www.jenkins.io/doc/book/pipeline/docker/ Using Docker with Pipeline,官方文档]
 
[https://www.jenkins.io/doc/book/pipeline/docker/ Using Docker with Pipeline,官方文档]
 +
 +
[https://blog.csdn.net/a10703060237/article/details/105574998  超详细!手把手教你用Jenkins pipeline + docker 打造前后端持续集成环境]
 +
 +
[https://www.cnblogs.com/Dev0ps/p/10502803.html  Jenkins+Docker+Git+Harbor流水线打包 ]
 +
 +
 +
[https://www.cnblogs.com/zoujiaojiao/p/13277532.html  jenkins pipeline 调用远程docker宿主机进行打包镜像和推送镜像 ]
 +
 
=是Blue Ocean=
 
=是Blue Ocean=
 
https://www.jenkins.io/zh/doc/book/blueocean/
 
https://www.jenkins.io/zh/doc/book/blueocean/
第310行: 第552行:
 
[https://www.cnblogs.com/hellxz/p/pipeline_maven_build.html  Jenkins教程(四)安装BlueOcean与Maven构建 ]
 
[https://www.cnblogs.com/hellxz/p/pipeline_maven_build.html  Jenkins教程(四)安装BlueOcean与Maven构建 ]
  
=see also=
+
=references=
 +
 
 +
[https://blog.zhimma.com/2019/02/16/%E4%BD%BF%E7%94%A8Jenkins%E7%9A%84Pipeline%E5%8F%91%E5%B8%83%E4%BB%A3%E7%A0%81%E8%87%B3%E8%BF%9C%E7%A8%8B%E6%9C%8D%E5%8A%A1%E5%99%A8/  使用Jenkins的Pipeline发布代码至远程服务器 ]
 +
 
 
[https://www.cnblogs.com/mingerlcm/p/12790884.html Jenkins Pipeline介绍]
 
[https://www.cnblogs.com/mingerlcm/p/12790884.html Jenkins Pipeline介绍]
  
第329行: 第574行:
  
 
[https://www.cnblogs.com/itech/p/12747740.html  Jenkins pipeline之声明式的jenkinsfile ]
 
[https://www.cnblogs.com/itech/p/12747740.html  Jenkins pipeline之声明式的jenkinsfile ]
 +
 +
 +
[https://blog.zhimma.com/2019/02/20/Jenkins-%E5%9F%BA%E7%A1%80%E6%96%B9%E6%B3%95Basic-Steps/  Jenkins-基础方法Basic Steps ]
 +
 +
[https://githubmota.github.io/2018/07/24/2018-07-24-Jenkins_pipeline_share/ Jenkins Pipeline实践分享]
 +
 +
[https://blog.zhimma.com/2019/02/18/Jenkins-Pipeline%E8%AF%AD%E6%B3%95%E5%85%A5%E9%97%A8/  Jenkins-Pipeline语法入门 ]
 +
 +
 +
[https://testerhome.com/topics/11646?order_by=like&  持续集成 使用 Jenkins Pipeline 迁移 Job ]
 
[[category:ops]] [[category:devops]]
 
[[category:ops]] [[category:devops]]

2021年10月13日 (三) 11:36的最新版本

Jenkins Pipeline 简介

https://www.jenkins.io/zh/doc/book/pipeline/ Jenkins pipeline 是 Jenkins 2.0 的精髓,,是帮助 Jenkins 实现 CI 到 CD 转变的重要角色。

注意 现在程序员的代码一般在pipeline的step里面 而不是以前的在代码管理了啦, 代码管理那现在是管理jenkinsfile etc

简单来说,就是一套运行于 Jenkins 上的工作流框架,将原本独立运行于单个或者多个节点的任务连接起来,实现单个任务难以完成的复杂发布流程。

Pipeline 的实现方式是一套 Groovy DSL,任何发布流程都可以表述为一段 Groovy 脚本,并且 Jenkins 支持从代码库直接读取脚本,从而实现了 Pipeline as Code 的理念。

jenkins2 pipeline入门

官方文档 流水线可以通过以下任一方式来创建:

   通过 Blue Ocean - 在 Blue Ocean 中设置一个流水线项目后,Blue Ocean UI 会帮你编写流水线的 Jenkinsfile 文件并提交到源代码管理系统。
   通过经典 UI - 你可以通过经典 UI 在 Jenkins 中直接输入基本的流水线。
   在源码管理系统中定义 - 你可以手动编写一个 Jenkinsfile 文件,然后提交到项目的源代码管理仓库中。[3]

使用两种方式定义流水线的语法是相同的。尽管 Jenkins 支持在经典 UI 中直接进入流水线,但通常认为最好的实践是在 Jenkinsfile 文件中定义流水线,Jenkins 之后会直接从源代码管理系统加载。

Jenkins Pipeline 支持两种语法



My-pipeline-job01 ->流水线语法    我好像没怎么用 

Jenkins Pipeline 支持两种语法,一种 Declarative Pipeline(声明式),一种 ScriptedPipeline(脚本式)。

安装pipeline相关插件  全部要显示为Success  pending是不行的


声明式的 Pipeline 限制用户使用严格的预选定义的结构,是一种声明
式的编程模型,对比脚本式的 Pipeline 学习起来更加简单;

脚本式的 Pipeline 限制比较少,结构和语法的限制由 Groovy 本身决定,是一种命令式的编程模型。
所以我们学习使用声明式的方式编写 jenkinsfile。
一般来说 jenkinsfile 会被放在代码库的根目录下。

当然也可以在 Web 页面定义。

下面是两种不同方式的 jenkinsfile 示例

Jenkinsfile (声明式)


pipeline { 
    agent any
    stages { 
        stage('Build') { 
            steps { 
                echo 'Building..' 
                } 
            } 
            stage('Test') { 
                steps { 
                    echo 'Testing..' 
                } 
            } 
            stage('Deploy') { 
                steps { 
                    echo 'Deploying....' 
                } 
            } 
        }
    }

前面我们说过,声明式的Pipeline有严格的预定义格式结构,有固定的格式,外层必须是pipeline{},
紧接着是 agent  就是节点node ,agent也是固定的,pipeline紧跟着进来 一定是agent 参考上面的格式  后面的any是任何节点还是其中一个节点,指定某一个节点是自己指定,通过标签自己来指定节点

指示 Jenkins 分配一个执行器和工作空间来执行下面的 Pipeline,

 stages和steps是申明式Jenkinsfile必须的,stages是一个个阶段,所有的stage必须要定义在stages里,

stages(‘’) 括号里面是名称,这个阶段是什么名称,stages这个名称不能重复,同一个stage名称只能有一个

每一个stage下的 step 要定义在一个 steps 里,stages里面包含了step,具体的执行步骤都写在step里面 ,一行一个,可以写多行

Jenkinsfile(脚本式)


node { 
    stage('Build') { 
        // 
    } 
    stage('Test') { 
        // 
    } 
    stage('Deploy') { 
        // 
    } 
}

在脚本式 jenkinsfile 里,你可以定义一个 node 或者多个 node 块,然后在 node 块里
定义你的 stage,在 stage 里定义你的 step 即可

git timeout

#有时候会timout 于是 你懂的 配置一下  在pepeline脚本中的extensions(扩展插件)中添加设置timeout时间为30min,默认为10min,即可解决
pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                // Get some code from a Git repository
                 checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [[$class:'CheckoutOption',timeout:30]], userRemoteConfigs: [[credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: '[email protected]:php/project.git']]])
                //checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [], userRemoteConfigs: [[credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: '[email protected]:php/project.git']]])



#my eg  现在这个问题是有个项目的代码非常大的  程序哥说平时都拉半个小时的 于是只能配置为 12000,不然老是 fail
steps {
                // Get some code from a Git repository  git clone timeout  troubleshooting 
                sh "git config --global http.postBuffer 1048576000"
                sh "git config --list"
                //git branch: 'beta', credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: '[email protected]:php/product-server.git'
                checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [[$class:'CheckoutOption',timeout:3000],[$class: 'CloneOption', timeout: 12000]], userRemoteConfigs: [[credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: '[email protected]:php/product-server.git']]])


#eg 
checkout([
      $class: 'GitSCM', branches: [[name: "${branch}"]],
      doGenerateSubmoduleConfigurations: false,extensions: [[$class:'CheckoutOption',timeout:30],[$class:'CloneOption',depth:0,noTags:false,reference:'',shallow:false,timeout:30]], submoduleCfg: [],
      userRemoteConfigs: [[credentialsId: 'xxxxx', url: "${project_url}"]]

checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [[$class:'CheckoutOption',timeout:3000],[$class: 'CloneOption', timeout: 12000]], userRemoteConfigs: [[credentials


脚本式pipeline 

node {

stage('clone') { // for display purposes
    // Get some code from a GitHub repository
    checkout([$class: 'GitSCM',
        branches: [[name: '*/master']],
        extensions: [[$class: 'CloneOption', timeout: 120]],
        gitTool: 'Default', 
        userRemoteConfigs: [[url: 'https://github.com/LimeSurvey/LimeSurvey.git']]
    ])
}

stage('zip'){
    zip zipFile: './publish.zip',
        archive: true
}}


Pipeline设置默认超时时间,并指定变量时自动更改超时时间

git clone克隆过早结束解决方法(git clone early EOF error solution)

git 解决 fatal- 过早的文件结束符(EOF) fatal- index-pack failed

Configure git timeout on Jenkins pipeline with Classic UI

常用例子

eg


举个栗子,保留历史构建次数的。将下面的块结构体放入 pipeline 中即可。

// 设置保留构建次数
options {
    buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
}

清理空间

https://plugins.jenkins.io/ws-cleanup/

Jenkins管道如何更改到另一个文件夹

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                // Get some code from a Git repository
                checkout([$class: 'GitSCM', branches: [[name: '*/beta']], extensions: [[$class:'CheckoutOption',timeout:30]], userRemoteConfigs: [[credentialsId: '7a624fab-88a7-4b0e-9e6d-1a8dff5f9732', url: 'git@git./server.git']]])

                dir("${env.WORKSPACE}/www/l.com"){
                    //sh "composer install"
                    sh "rm -rf ${env.WORKSPACE}/www/l.com@tmp"
                    sh " echo git code ok "
                } 


                sh " rsync  -aqz --progress --exclude-from=/backup/upline/exclude  ${env.WORKSPACE}/www/  [email protected]:/data/2"
                sh " ssh [email protected]   chown -R www.www  /data/2"

            } 

Jenkins pipeline how to change to another folder


关于groovy:Jenkins管道如何更改到另一个文件夹

pipeline 多行执行shell 命令


#但是今天独立拿出来 rsync 居然不成功 怪 里面有变量  要用""" """
                dir("${env.WORKSPACE}/www/client.cfb.com"){
                    sh '''cnpm install
                       cnpm install core-js@2
                       npm run deploy:beta
                    
                    '''
                    

                }




                sh """
                    rsync  -aqz --progress --exclude-from=/backup/upline/exclude ${env.WORKSPACE}/www/im.com/deploy   [email protected]:/data/
                    ssh [email protected]   chown -R apache.apache   /data/nginx/proxy/sscf-crm-im-proxy
                        


                """







Jenkins Pipeline」- 执行 Shell 命令

https://www.jenkins.io/zh/doc/pipeline/tour/running-multiple-steps/

https://stackoverflow.com/questions/44330148/run-bash-command-on-jenkins-pipeline/

jenkins管道:带管道的多行Shell命令

IDE vscode

添加 Jenkins Pipeline Linter Connector

进阶advance

Docker+Jenkins+Pipeline实现持续集成-模板

.jenkins.io/zh/doc/book 流水线入门

jenkins.io 流水线入门

Jenkins 声明式流水线的语法错误检查

Pipeline 语法生成器

流水线语法


Jenkins2 下载与启动 jenkins2 插件安装 jenkins2 hellopipeline jenkins2 pipeline介绍 jenkins2 javahelloworld jenkins2 groovy入门 jenkins2 pipeline入门 jenkins2 pipeline高级 jenkins2 Jenkinsfile jenkins2 multibranch jenkins2 Jenkinsfile和load jenkins2 groovy脚本参考 jenkins2 pipeline实例 jenkins2 pipeline插件的10个最佳实践 jenkins2 pipeline 语法快速参考

https://www.cnblogs.com/itech/category/245402.html?page=3


jenkins2 pipeline高级

pipeline for example

其实就是有点像share library 流水线 -->定义

然后有个叫jenkinsfile

这个不错 反正最后都是写流水脚本 jenkinsfile Pipeline流水线及分布式流水线发布PHP项目及JAVA项目

jenkins.io使用Maven构建Java应用程序

Jenkins--pipline 流水线部署Java后端项目

本地java代码上传Gitlab仓库

Jenkins自动部署发布Java代码(完整教程

java sprint boot

Jenkins Pipeline 部署 SpringBoot 应用

java

修改/etc/profile文件,添加JAVA_HOME

vi /etc/profile
在文件的最后面,加上以下代码
export JAVA_HOME=/java/jdk1.8.0_171
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

#me on  kali xps 
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export M2_HOME=/usr/local/maven3
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin

maven

wget -c https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz 
tar zxf apache-maven-3.8.1-bin.tar.gz 
mv apache-maven-3.1.1 /usr/local/maven3 

vi /etc/profile然后还需要 配置环境变量。 #在适当的位置添加

export M2_HOME=/usr/local/maven3
export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin

保存退出后运行下面的命令使配置生效,或者重启服务器生效。
source /etc/profile

验证版本
mvn -v

出现maven版本即成功

阿里云源

<mirrors>
    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>
</mirrors>

安装Jenkins部署SpringBoot应用

jenkins 安装过程省略

登陆之后进入Manage Jenkins -> Global Tool Configuration 中进行配置Maven,Git,JDK 可能不同环境有小许要修改

最优雅的Docker+Jenkins pipeline部署Spring boot项目

新建Pipeline 项目

新建Item --> 名就叫 01_Eureka 再选中pipeline 最后确定 -->

配置Git仓库: http://mygitlab.com/root/01_eureka.git


包目录 
van@myxps:~$ ls data/jenkins/workspace/01_Eureka/eureka-server/target/eureka-server-1.0.0.jar
data/jenkins/workspace/01_Eureka/eureka-server/target/eureka-server-1.0.0.jar


tree .
.
└── jenkins_files
    └── 01_eureka

1 directory, 1 file

#脚本式 ,node:代表单台服务器的节点
cat jenkins_files/01_eureka

node {
   def mvnHome
   def workspace = pwd()
   def project_name = 'eureka-server-1.0.0.jar'
   def project_log = 'eureka-server-1.0.0.log'
   def project_home = 'app-centre/eureka-server'
   def vm_ip = 'xxx.xxx.xxx.xxx'
   def vm_port = '22'
   def vm_user = 'root'
   //代码获取
   stage('Preparation') { // for display purposes
	  git branch: 'master',
	  url:' https://gitee.com/didispace/didi-eureka-server.git'
   }
   //构建
   stage('Build') {
      // Run the maven build
      if (isUnix()) {
         sh "/usr/local/maven3/bin/mvn -Dmaven.test.skip=true clean package"
 
      } else {
         bat(/mvn -Dmaven.test.skip=true clean package/)
      }
   }
   
   //移动
   stage('MV') {
     sh "mv ${project_home}/target/${project_name} /usr/local/src/"
   }
   
   //上传到服务器
   stage('Upload VM') {
     sh "scp -P ${vm_port} /usr/local/src/${project_name} ${vm_user}@${vm_port}:/usr/local/src/bk"
	 //sh "ssh -p ${vm_port} ${vm_user}@${vm_ip} 'nohup java -jar /usr/local/src/${project_name} >> ${project_log} '"
   }
   
   
  //运行JAR包
  stage('Run') {
	 //sh "if (ps -ef| grep java|grep ${project_name})then (ps -ef| grep java|grep ${project_name}| awk '{print \$2}'|xargs kill -9) fi"
     sh "ssh -p ${vm_port} ${vm_user}@${vm_ip} 'nohup java -jar /usr/local/src/${project_name} >${project_log} 2>&1 &'"
  }
}

流水线选项卡 定义 : pipeline script from SCM SCM repository URl http://mygitlab.com/root/01_eureka.git

Credentials 你的用户和密码

指定分支(为空时代表any) 我这里为 */main

脚本路径 jenkins_files/01_eureka


最简单的pipeline maven java

Jenkinsfile入门:Pipeline使用Maven构建java项目

源码及Jenkinsfile
https://github.com/evan886/pipeline-maven-eg


分支 main  注意了

checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[credentialsId: '55c4819e-ac29-47c8-97d0-528252de42ef', url: 'http://mygitlab.com/root/pipeline-maven-eg']]])




就是作测试居然遇到个坑 哈哈 on my kali 
[ERROR] COMPILATION ERROR : 

[INFO] -------------------------------------------------------------

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?



maven settings.xml 


居然用jdk11 可以去编译pom.xml 1.8的 

jenkins 可能要的配置
manage jenkins -->configure system -->全局属性--  勾上 environment variables  

键 JAVA_HOME  
值 /usr/lib/jvm/java-11-openjdk-amd64




cat  /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64


jenkins/workspace/pipeline-maven-eg/target# java  -jar  pipeline-demo-0.0.1-SNAPSHOT.jar

http://localhost:40080/




see also springboot

生成流水脚本 Jenkins构建Maven项目 【Pipeline流水线方式构建


Jenkins Pipeline 部署 SpringBoot 应用

最优雅的Docker+Jenkins pipeline部署Spring boot项目

Jenkins Pipeline+Maven+Gitlab持续集成构建

Pipeline流水线+ Docker(docker java应用)实现自动化CI/CD发布Java项目

Jenkins+Pipeline流水线+Docker实现自动化CI/CD发布Java项目

vue

最优雅的Docker+Jenkins pipeline部署vue项目,前端项目都可参考

使用Docker+Jenkins+Pipeline将Vue项目部署到Nginx服务器

war tomcat

Pipeline自动化构建发布Java tomcat项目 声明式

pipeline php

Jenkins + pipeline + Git + PHP (九) 这个对的

k8s系列 – jenkins pipeline打包php docker镜像保存harbor仓库

Pipeline流水线及分布式流水线发布PHP项目及JAVA项目

项目案例之Pipeline流水线及流水线发布PHP项目(二)

Jenkins的Pipeline流水线

项目案例之Pipeline流水线及流水线发布PHP项目

docker

Using Docker with Pipeline,官方文档

超详细!手把手教你用Jenkins pipeline + docker 打造前后端持续集成环境

Jenkins+Docker+Git+Harbor流水线打包


jenkins pipeline 调用远程docker宿主机进行打包镜像和推送镜像

是Blue Ocean

https://www.jenkins.io/zh/doc/book/blueocean/

Blue Ocean 重新思考Jenkins的用户体验,从头开始设计Jenkins Pipeline, 但仍然与自由式作业兼容,Blue Ocean减少了混乱而且进一步明确了团队中每个成员 Blue Ocean 的主要特性包括:

   持续交付(CD)Pipeline的 复杂可视化 ,可以让您快速直观地理解管道状态。
   Pipeline 编辑器 - 引导用户通过直观的、可视化的过程来创建Pipeline,从而使Pipeline的创建变得平易近人。
   个性化 以适应团队中每个成员不同角色的需求。
   在需要干预和/或出现问题时 精确定位 。 Blue Ocean 展示 Pipeline中需要关注的地方, 简化异常处理,提高生产力
   本地集成分支和合并请求, 在与GitHub 和 Bitbucket中的其他人协作编码时实现最大程度的开发人员生产力。

简言之:简化复杂可视化,提供更个性直观的界面,可以精准定位构建失败的位置

Jenkins教程(四)安装BlueOcean与Maven构建

references

使用Jenkins的Pipeline发布代码至远程服务器

Jenkins Pipeline介绍

jenkins从头到尾 目录

Jenkins Pipeline示例

使用 pipeline 实现 monitor 仓库代码的发布

Jenkins pipeline jenkinsfile的两种写作方式声明式和脚本式

基于Jenkins Pipeline自动化部署知道个过程而已


Jenkins + Pipeline 自动化部署项目

Jenkins + Pipeline 构建流水线发布

Jenkins pipeline之声明式的jenkinsfile


Jenkins-基础方法Basic Steps

Jenkins Pipeline实践分享

Jenkins-Pipeline语法入门


持续集成 使用 Jenkins Pipeline 迁移 Job