3.6.1、安装配置ansible
略
3.6.2、配置共享库
Jenkinslib/src/org/devops/deploy.groovy
package org.devops
//ansible
def AnsibleDeploy(host,func){
//传入主机组,指令
sh "ansible ${host} ${func}"
}
3.6.3、Jenkinsfile引用共享库
#!groovy
//引用Library库
@Library('jenkinslib@master') _
//引用构建共享库
def build = new org.devops.build()
//引入发布共享库
def deploy = new org.devops.deploy()
//引入参数
String buildType = "${env.buildType}" //引用参数
String buildShell = "${env.buildShell}" //引用参数
String deployHost = "${env.deployHost}" //引用参数
String deployShell = "${env.deployShell}" //引用参数
pipeline {
agent {
node {
label "master" //构建主机
}
}
stages {
stage("Build") {
steps {
script {
//引入构建共享库内函数
build.Build(buildType,buildShell)
//引用发布共享库内函数
deploy.AnsibleDeploy("${deployHost}","-m ${deployShell}")
}
}
}
}
}
3.6.4、Jenkins配置
git地址:
https://github.com/liuhaoliuxue/Jenkinslib.git