Skip to content
SRE运维进阶之路SRE运维进阶之路
github icon
  • Jenkins

    • Jenkins 学习笔记
      • 1 Jenkins 简介

        • 1.1 DevOps、CI、CD都是什么鬼?
          • 1.2 Jenkins简介
          • 2 安装 Jenkins

            • 2.1 yum 安装 jenkins
              • 2.2 war 包安装 jenkins
                • 2.3 使用 ansible 安装 jenkins
                  • 2.4 使用docker安装jenkins
                  • 3 使用 Jenkins

                    • 3.1 Jenkins用户权限管理
                      • 3.2 访问 API
                      • 4 流水线核心语法

                        • 4.1 开始编写Jenkinsfile
                          • 4.2 Jenkins流水线语法
                            • 4.3 Groovy 简明教程
                              • 4.4 Jenkins共享库应用
                                • 4.5 共享库之钉钉消息推送
                                  • 4.6 流水线开发工具
                                    • 片段生成器
                                      • 声明式语法生成器
                                        • 全局变量参考
                                          • env变量
                                            • currentbuild变量
                                            • 常用的方法
                                            • 4.7 pipeline 生产配置实例
                                              • 4.8 在 VS Code 中校验 Jenkinsfile
                                              • 5 流水线集成篇

                                                • 5.1 构建发布工具集成
                                                  • 5.2 用户认证系统集成
                                                  • 6 管理 jenkins

                                                    • 6.1 Jenkins 关闭和重启的实现方式
                                                    • 7 日常维护

                                                      • 7.1 Jenkins Job迁移
                                                      • 8 Jenkins 常见问题
                                                      • Ansible

                                                        • Ansible 学习笔记
                                                          • 1 初识Ansible
                                                            • 2 Ansible Inventory配置详解
                                                              • 3 Ansible Ad-hoc命令集

                                                                • 3.1 Ansible Ad-hoc 常用命令集
                                                                  • 3.2 Ansible lineinfile模块详解
                                                                  • 4 Ansible Playbook

                                                                    • 4.1 Playbook的结构及handler用法
                                                                      • 4.2 Playbook循环语句
                                                                        • 4.3 Playbook条件语句
                                                                          • 4.4 Playbook高级用法
                                                                            • 4.5 Playbook之tags
                                                                              • 4.6 巧用Roles
                                                                                • 4.7 Jinja2 模板
                                                                                  • 4.8 yaml语法
                                                                                  • 5 Ansible变量

                                                                                    • 5.1 自定义变量
                                                                                      • 5.2 Fact变量
                                                                                        • 5.3 魔法变量
                                                                                          • 5.4 使用lookup生成变量
                                                                                            • 5.5 使用vault配置加密
                                                                                            • 6 Ansible使用优化
                                                                                              • 7 常见问题
                                                                                                • 8 综合项目

                                                                                                  • 使用 ansible 快速安装 k8s 机器

                                                                                                4.6 流水线开发工具

                                                                                                author iconClaycalendar icon2021年6月3日category icon
                                                                                                • 自动化工具
                                                                                                tag icon
                                                                                                • Jenkins
                                                                                                timer icon大约 2 分钟

                                                                                                此页内容
                                                                                                • 片段生成器
                                                                                                • 声明式语法生成器
                                                                                                • 全局变量参考
                                                                                                  • env变量
                                                                                                  • currentbuild变量
                                                                                                • 常用的方法

                                                                                                # 4.6 流水线开发工具

                                                                                                转载自:流水线开发工具 | 泽阳open in new window

                                                                                                您好,本模块主要了解在流水线中常用的方法😀


                                                                                                # 片段生成器

                                                                                                使用片段生成器可以根据个人需要生成方法,有些方法来源于插件,则需要先安装相关的插件才能使用哦。

                                                                                                imagesopen in new window

                                                                                                填写好参数后,点击生成,然后复制粘贴到Jenkinsfileimagesopen in new window

                                                                                                # 声明式语法生成器

                                                                                                imagesopen in new window

                                                                                                # 全局变量参考

                                                                                                imagesopen in new window

                                                                                                # env变量

                                                                                                BUILD_NUMBER          //构建号
                                                                                                BUILD_ID              //构建号
                                                                                                BUILD_DISPLAY_NAME    //构建显示名称
                                                                                                JOB_NAME              //项目名称
                                                                                                              
                                                                                                EXECUTOR_NUMBER       //执行器数量
                                                                                                NODE_NAME             //构建节点名称
                                                                                                WORKSPACE             //工作目录
                                                                                                JENKINS_HOME          //Jenkins home
                                                                                                JENKINS_URL           //Jenkins地址
                                                                                                BUILD_URL             //构建地址
                                                                                                JOB_URL               //项目地址
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4
                                                                                                5
                                                                                                6
                                                                                                7
                                                                                                8
                                                                                                9
                                                                                                10
                                                                                                11
                                                                                                12

                                                                                                # currentbuild变量

                                                                                                result  currentResult   //构建结果
                                                                                                displayName      //构建名称  #111
                                                                                                description      //构建描述
                                                                                                duration         //持续时间
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4

                                                                                                # 常用的方法

                                                                                                json数据处理

                                                                                                def response = readJSON text: "${scanResult}"
                                                                                                println(scanResult)
                                                                                                
                                                                                                //原生方法
                                                                                                import groovy.json.*
                                                                                                
                                                                                                @NonCPS
                                                                                                def GetJson(text){
                                                                                                    def prettyJson = JsonOutput.prettyPrint(text) 
                                                                                                    new JsonSlurperClassic().parseText(prettyJson)
                                                                                                }
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4
                                                                                                5
                                                                                                6
                                                                                                7
                                                                                                8
                                                                                                9
                                                                                                10
                                                                                                11

                                                                                                使用凭据

                                                                                                withCredentials([string(credentialsId: "xxxxx", variable: "sonarToken")]) {
                                                                                                    println(sonarToken)
                                                                                                }
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3

                                                                                                下载代码

                                                                                                //Git
                                                                                                checkout([$class: 'GitSCM', branches: [[name: "brnachName"]], 
                                                                                                            doGenerateSubmoduleConfigurations: false, 
                                                                                                            extensions: [], submoduleCfg: [], 
                                                                                                            userRemoteConfigs: [[credentialsId: "${credentialsId}", 
                                                                                                            url: "${srcUrl}"]]])
                                                                                                //Svn
                                                                                                checkout([$class: 'SubversionSCM', additionalCredentials: [], 
                                                                                                            filterChangelog: false, ignoreDirPropChanges: false, 
                                                                                                            locations: [[credentialsId: "${credentialsId}", 
                                                                                                            depthOption: 'infinity', ignoreExternalsOption: true, 
                                                                                                            remote: "${svnUrl}"]], workspaceUpdater: [$class: 'CheckoutUpdater']]
                                                                                                )
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4
                                                                                                5
                                                                                                6
                                                                                                7
                                                                                                8
                                                                                                9
                                                                                                10
                                                                                                11
                                                                                                12
                                                                                                13

                                                                                                展示报告

                                                                                                publishHTML([allowMissing: false, 
                                                                                                        alwaysLinkToLastBuild: false, 
                                                                                                        keepAll: true, 
                                                                                                        reportDir: './report/', 
                                                                                                        reportFiles: "a.html, b.html", 
                                                                                                        reportName: 'InterfaceTestReport', 
                                                                                                        reportTitles: 'HTML'])
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4
                                                                                                5
                                                                                                6
                                                                                                7

                                                                                                交互输入

                                                                                                def result = input  message: '选择xxxxx', 
                                                                                                                    ok: '提交',
                                                                                                                    parameters: [extendedChoice( description: 'xxxxx', 
                                                                                                                                                descriptionPropertyValue: '', 
                                                                                                                                                multiSelectDelimiter: ',', 
                                                                                                                                                name: 'failePositiveCases', 
                                                                                                                                                quoteValue: false, 
                                                                                                                                                saveJSONParameterToFile: false, 
                                                                                                                                                type: 'PT_CHECKBOX', 
                                                                                                                                                value: "1,2,3", 
                                                                                                                                                visibleItemCount: 99)]   
                                                                                                println(result)
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4
                                                                                                5
                                                                                                6
                                                                                                7
                                                                                                8
                                                                                                9
                                                                                                10
                                                                                                11
                                                                                                12

                                                                                                构建用户

                                                                                                wrap([$class: 'BuildUser']){
                                                                                                            echo "full name is $BUILD_USER"
                                                                                                            echo "user id is $BUILD_USER_ID"
                                                                                                            echo "user email is $BUILD_USER_EMAIL"
                                                                                                }
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4
                                                                                                5

                                                                                                制品上传

                                                                                                rtUpload (
                                                                                                        serverId: "artifactory01",
                                                                                                        spec:
                                                                                                            """{
                                                                                                            "files": [
                                                                                                                {
                                                                                                                "pattern": "report/a.html",
                                                                                                                "target": "${repoName}/a/b/v"
                                                                                                                }
                                                                                                            ]
                                                                                                            }"""
                                                                                                    )
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4
                                                                                                5
                                                                                                6
                                                                                                7
                                                                                                8
                                                                                                9
                                                                                                10
                                                                                                11
                                                                                                12

                                                                                                发送http请求

                                                                                                ApiUrl = "http://xxxxxx/api/project_branches/list?project=${projectName}"
                                                                                                Result = httpRequest authentication: 'xxxxxxxxx',
                                                                                                                         quiet: true, 
                                                                                                                         contentType: 'APPLICATION_JSON' ,  
                                                                                                                         url: "${ApiUrl}"
                                                                                                
                                                                                                1
                                                                                                2
                                                                                                3
                                                                                                4
                                                                                                5
                                                                                                edit icon编辑此页open in new window
                                                                                                上次编辑于: 2022/4/27 15:33:00
                                                                                                贡献者: clay-wangzhi
                                                                                                上一页
                                                                                                4.5 共享库之钉钉消息推送
                                                                                                下一页
                                                                                                4.7 pipeline 生产配置实例
                                                                                                备案号:冀ICP备2021007336号
                                                                                                Copyright © 2023 Clay