zoukankan      html  css  js  c++  java
  • jenkins持续集成3

    1.安装Pipeline插件,并初识

    • 1.启动Jenkins,打开浏览器http://localhost:8080,系统管理,用户名:chenshanju/123456

    • 2.系统管理-插件管理,安装pipeline插件
      <img src="https://img2018.cnblogs.com/blog/1418970/201810/1418970-20181014105903553-1820442974.png" width="600"

    • 3.配置maven环境
      系统管理-全局工具配置。
      如果本机未安装maven,名称设置为m3,选择安装maven
      如果本机已安装maven,名称设置为m3,填入maven安装路径

    • 4.创建pipeline项目,并构建。

    //pipeline script脚本
    node {
       def mvnHome
       stage('Preparation') { // for display purposes
          // Get some code from a GitHub repository
          //guan fang官方
          //git 'https://github.com/jglick/simple-maven-project-with-tests.git'
          git 'https://github.com/nbbull/demoProject.git'
          // Get the Maven tool.
          // ** NOTE: This 'M3' Maven tool must be configured
          // **       in the global configuration.           
          mvnHome = tool 'M3'
       }
       stage('Build') {
          // Run the maven build
          if (isUnix()) {
             sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
          } else {
             bat(/"${mvnHome}inmvn" -Dmaven.test.failure.ignore clean package/)
          }
       }
       stage('Results') {
          junit '**/target/surefire-reports/TEST-*.xml'
          archive 'target/*.jar'
       }
    }
    
    #声明式
    #!groovy
    
    pipeline {
        environment{
                mvnHome = tool 'M3'
            }
        agent any
        stages {
            stage ('Preparation'){
                steps{
                    git 'https://github.com/nbbull/demoProject.git'
                    
                }
            }
            stage ('Build'){
                steps{
                    script{
                    if (isUnix()) {
                        sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
                    } else {
                        bat(/"${mvnHome}inmvn" -Dmaven.test.failure.ignore clean package/)
                    }
                    }
                }
                
            }
            stage ('Results'){
                steps{
                    junit '**/target/surefire-reports/TEST-*.xml'
                    archive 'target/*.jar'
                }
            }
       }    
    }
    
    

    FAQ:

    1.声明式脚本包含方法的要放在script里面

    2.环境变量要方法哦pipeline里面,不能和pipeline平行

  • 相关阅读:
    c# 指针unsafe/fixed -- 【一】
    Windows消息大全(转)
    Windows消息过滤
    C#预编译
    c#摄像头编程实例 (转)
    多线程按顺序执行 (转)
    定位程序集
    无需写try/catch,也能正常处理异常 (转)
    无需Try catch 的UI事件封装类
    注册表修改安全策略
  • 原文地址:https://www.cnblogs.com/csj2018/p/9785759.html
Copyright © 2011-2022 走看看