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平行

  • 相关阅读:
    scala
    数据结构(01)
    基本算法(07)
    基本算法(06)
    基本算法(05)
    git pull文件时和本地文件冲突的问题
    获取两个日期之间的日期形成一个集合
    lombok的简单介绍(2)
    springboot启动报错
    逆向工程的创建
  • 原文地址:https://www.cnblogs.com/csj2018/p/9785759.html
Copyright © 2011-2022 走看看