場景:前端業務使用了微服務架構,需要在一個主項目中編譯打包所有子項目。

1、創建一個流水線任務
2、填寫項目描述
3、編寫 pipeline 腳本
pipeline {
agent any
stages {
stage("build console all") {
steps {
script {
def starting = 'prod-'
def ending = ""
def job_list = [
"woc-common",
"woc-ecs",
"woc-eip",
"woc-home",
"woc-person-center",
"woc-user-iam",
"woc-vpc",
"woc-console",
"woc-oss",
"woc-slb"
]
def branches = [:]
MAX_CONCURRENT = 4
//創建fifo
latch = new java.util.concurrent.LinkedBlockingDeque(MAX_CONCURRENT)
//往fifo中,填入最大個數元素
for(int i=0; i<MAX_CONCURRENT; i++)
latch.offer("$i")
for(int i=0; i<job_list.size(); i++) {
def name = starting + job_list[i] + ending
branches[name] = {
def thing = null
waitUntil {
//獲取一個資源
thing = latch.pollFirst();
return thing != null;
}
try {
//執行job
build(job: name, propagate: false)
}
finally {
//釋放一個資源
latch.offer(thing)
}
}
}
timestamps {
parallel branches
}
}
}
}
}
}
參考:
http://www.lujun.org.cn/?p=4025
https://www.cnblogs.com/sparkdev/archive/2018/10/04/9742739.html
https://www.cnblogs.com/sparkdev/p/7617765.html
https://www.w3cschool.cn/jenkins/jenkins-c7qs28n5.html
https://www.cnblogs.com/zangxueyuan/p/9207739.html
