Commit 4ab09fe5 authored by daidekun's avatar daidekun

增加数组分隔方法

parent 6cd795ee
import org.qg.ansible.*
def call(body) {
......@@ -12,24 +13,12 @@ def call(body) {
def dataCenter = env.data_center
def machines = env.hosts
def _utils = new org.qg.ansible.Utils()
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
def partition(array, size) {
def partitions = []
int partitionCount = array.size() / size
partitionCount.times { partitionNumber ->
def start = partitionNumber * size
def end = start + size - 1
partitions << array[start..end]
}
if (array.size() % size) partitions << array[partitionCount * size..-1]
return partitions
}
node {
stage('Clean') {
deleteDir()
......@@ -43,7 +32,7 @@ def call(body) {
stage('Deploy') {
arr_machines = machines.split(",")
machines_list = partition(arr_machines, 1)
machines_list = _utils.partition(arr_machines, 1)
echo machines_list
sh "ansible-playbook /etc/ansible/nginx_remove.yml -e project_name=${envType}.${projectName} -e data_center=${dataCenter} -e machines=${machines} -vv"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment