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}\bin\mvn" -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}\bin\mvn" -Dmaven.test.failure.ignore clean package/)
                }
                }
            }
            
        }
        stage ('Results'){
            steps{
                junit '**/target/surefire-reports/TEST-*.xml'
                archive 'target/*.jar'
            }
        }
   }    
}

FAQ:

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

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

转载于:https://www.cnblogs.com/csj2018/p/9785759.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值