zoukankan      html  css  js  c++  java
  • Jenkins Pipeline语法

    流水线总体语法

              

     指定node部分

            

       stages阶段

              

        post定义

             

    paramters参数

         

      trigger触发器

        

      tool 语法

         

    input 语法

        

      when 语法

        

     parallel 语法

       

    sharelibary共享库使用

         1.jenkins先安装sharelibary插件

           

          2.共享库项目有自己特定的目录组织结构

         

             vars目录和resource目录可以不要,但是src目录是必须要存在的

           

       常用的DSL语法

          1.读取json对象

              

          2.读取jenkins中的凭据信息

             

          3.checkout

              

         4.publishHTML

         5.input

         6.httpRequest

            1.需要首先安装jenkins http request插件

         

            

          7.email 发邮件

    pipeline {
       agent any
    
       tools {
          // Install the Maven version configured as "M3" and add it to the path.
          maven "M2"
       }
    
       stages {
          stage('GetCode'){
             steps {
                // Get some code from a GitHub repository
                git credentialsId: 'yxgitlab', url: 'https://1920.111:8090/tf-as/h5-new.git'
    
                // To run Maven on a Windows agent, use
                // bat "mvn -Dmaven.test.failure.ignore=true clean package"
             }
    
             post {
                // If Maven was able to run the tests, even if some of the test
                // failed, record the test results and archive the jar file.
                success {
                    
                  print("getCode success")
                }
             }
          }
          stage("Build"){
               steps {
                  script {
                      sh "cd /var/lib/jenkins/workspace/sdc-h5"
                      sh "npm config set strict-ssl false"
                      sh "npm install --registry=https://registry.npm.taobao.org"
                      sh "npm install node-sass --unsafe-perm --save-dev --registry=https://registry.npm.taobao.org"
                      sh "npm run build:sit"
                  }
                }
          }
          
          stage("Deploy"){
               steps {
                  script {
                      sh "ansible webservers --user=admin -m copy -a 'src=/var/lib/jenkins/workspace/sdc-h5/dist/ dest=/home/admin/runtime/nginx/html/'"
                  }
                }
                
               post {
                // If Maven was able to run the tests, even if some of the test
                // failed, record the test results and archive the jar file.
                success {
                    
                   print("Deploy Success")
                   emailext (
                    subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
                    body: """构建成功""",
                    to: "cfgitlab_an@163.com,724627@qq.com",
                    from: "cfgiab_in@163.com"
                   )
                }
                
                failure {
                
                   emailext body: '''<!DOCTYPE html>    
                    <html>    
                    <head>    
                    <meta charset="UTF-8">    
                    <title>${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志</title>    
                    </head>    
                        
                    <body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"    
                        offset="0">    
                        <table width="95%" cellpadding="0" cellspacing="0"  style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">    
                            <tr>    
                                本邮件由系统自动发出,无需回复!<br/>            
                                各位同事,大家好,以下为${PROJECT_NAME }项目构建信息</br> 
                                <td><font color="#CC0000">构建结果 - ${BUILD_STATUS}</font></td>   
                            </tr>    
                            <tr>    
                                <td><br />    
                                <b><font color="#0B610B">构建信息</font></b>    
                                <hr size="2" width="100%" align="center" /></td>    
                            </tr>    
                            <tr>    
                                <td>    
                                    <ul>    
                                        <li>项目名称 : ${PROJECT_NAME}</li>    
                                        <li>构建编号 : 第${BUILD_NUMBER}次构建</li>    
                                        <li>触发原因: ${CAUSE}</li>    
                                        <li>构建状态: ${BUILD_STATUS}</li>    
                                        <li>构建日志: <a href="${BUILD_URL}console">${BUILD_URL}console</a></li>    
                                        <li>构建  Url : <a href="${BUILD_URL}">${BUILD_URL}</a></li>    
                                        <li>工作目录 : <a href="${PROJECT_URL}ws">${PROJECT_URL}ws</a></li>    
                                        <li>项目  Url : <a href="${PROJECT_URL}">${PROJECT_URL}</a></li>    
                                    </ul>    
                    
                    <h4><font color="#0B610B">失败用例</font></h4>
                    <hr size="2" width="100%" />
                    $FAILED_TESTS<br/>
                    
                    <h4><font color="#0B610B">最近提交(#$SVN_REVISION)</font></h4>
                    <hr size="2" width="100%" />
                    <ul>
                    ${CHANGES_SINCE_LAST_SUCCESS, reverse=true, format="%c", changesFormat="<li>%d [%a] %m</li>"}
                    </ul>
                    详细提交: <a href="${PROJECT_URL}changes">${PROJECT_URL}changes</a><br/>
                    
                                </td>    
                            </tr>    
                        </table>    
                    </body>    
                    </html>''', 
                subject: '构建通知:${BUILD_STATUS} - ${PROJECT_NAME} - Build # ${BUILD_NUMBER} !', 
                to: '12727@qq.com',
                from: "cfgi_admin@163.com"
                }
             }
          }
       }
    }
    发送邮件流水线
          stage("Deploy"){
               steps {
                  script {
                      sh "ansible webservers --user=admin -m copy -a 'src=/var/lib/jenkins/workspace/sdc-h5/dist/ dest=/home/admin/runtime/nginx/html/'"
                  }
                }
                
               post {
                // If Maven was able to run the tests, even if some of the test
                // failed, record the test results and archive the jar file.
                success {
                   print("Deploy Success")
                }
                always {
                                emailext body: '''<!DOCTYPE html>    
                    <html>    
                    <head>    
                    <meta charset="UTF-8">    
                    <title>${ENV, var="JOB_NAME"}-第${BUILD_NUMBER}次构建日志</title>    
                    </head>    
                        
                    <body leftmargin="8" marginwidth="0" topmargin="8" marginheight="4"    
                        offset="0">    
                        <table width="95%" cellpadding="0" cellspacing="0"  style="font-size: 11pt; font-family: Tahoma, Arial, Helvetica, sans-serif">    
                            <tr>    
                                本邮件由系统自动发出,无需回复!<br/>            
                                各位同事,大家好,以下为${PROJECT_NAME }项目构建信息</br> 
                                <td><font color="#CC0000">构建结果 - ${BUILD_STATUS}</font></td>   
                            </tr>    
                            <tr>    
                                <td><br />    
                                <b><font color="#0B610B">构建信息</font></b>    
                                <hr size="2" width="100%" align="center" /></td>    
                            </tr>    
                            <tr>    
                                <td>    
                                    <ul>    
                                        <li>项目名称 : ${PROJECT_NAME}</li>    
                                        <li>构建编号 : 第${BUILD_NUMBER}次构建</li>    
                                        <li>触发原因: ${CAUSE}</li>    
                                        <li>构建状态: ${BUILD_STATUS}</li>    
                                        <li>构建日志: <a href="${BUILD_URL}console">${BUILD_URL}console</a></li>    
                                        <li>构建  Url : <a href="${BUILD_URL}">${BUILD_URL}</a></li>    
                                        <li>工作目录 : <a href="${PROJECT_URL}ws">${PROJECT_URL}ws</a></li>    
                                        <li>项目  Url : <a href="${PROJECT_URL}">${PROJECT_URL}</a></li>    
                                    </ul>    
                    
                    <h4><font color="#0B610B">失败用例</font></h4>
                    <hr size="2" width="100%" />
                    $FAILED_TESTS<br/>
                    
                    <h4><font color="#0B610B">最近提交(#$SVN_REVISION)</font></h4>
                    <hr size="2" width="100%" />
                    <ul>
                    ${CHANGES_SINCE_LAST_SUCCESS, reverse=true, format="%c", changesFormat="<li>%d [%a] %m</li>"}
                    </ul>
                    详细提交: <a href="${PROJECT_URL}changes">${PROJECT_URL}changes</a><br/>
                    
                                </td>    
                            </tr>    
                        </table>    
                    </body>    
                    </html>''', 
                subject: '构建通知:${BUILD_STATUS}-${PROJECT_NAME}-Build # ${BUILD_NUMBER} !', 
                to: '1247@qq.com',
                from: "cadmin@163.com"
                
                }
                
                failure {
                  print("Deploy Fail")
    
                }
             }
          }
    邮件

         8.jenkins流水线语法自动生成

            

        

         

  • 相关阅读:
    cmake 基本命令
    webpack4下import()模块按需加载,打包按需切割模块,减少包体积,加快首页请求速度
    内容安全策略(CSP)详解
    内网穿透访问Vue项目的时候出现Invalid Host header解决办法
    webpack3 项目升级 webpack4
    vue-multi-module【多模块集成的vue项目,多项目共用一份配置,可以互相依赖,也可以独立打包部署】
    JS的数据类型判断函数、数组对象结构处理、日期转换函数,浏览器类型判断函数合集
    使用模块化工具打包自己开发的JS库(webpack/rollup)对比总结
    基于AlipayJSBridge封装的H5网页支付宝打赏、网站打赏、个人免签支付,支付宝转账打赏支付组件
    whistle替代Fiddler调试远程服务器代码使用教程
  • 原文地址:https://www.cnblogs.com/yxh168/p/13068627.html
Copyright © 2011-2022 走看看