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

上一篇:KVM中Linux虚拟机的硬盘添加方法


下一篇:Linux虚拟机添加硬盘