CICD | Jenkins & Gitlab集成:WebHook触发构建 (2)

根据commits,定义patternMap,匹配到指定正则文件格式,构建指定组件。

def modifiedFile = []; for (commit in commits) { modifiedFile.addAll(commit.getAt("added").findAll()) modifiedFile.addAll(commit.getAt("modified").findAll()) modifiedFile.addAll(commit.getAt("removed").findAll()) } def buildComponents = new HashSet(); def patternMap = ['mark-engine-manager/.*': 'manager', 'mark-tools/.*': 'web','mark-engine-dm/.*':'dm','mark-engine-web/.*':'web', 'mark-engine-uc/.*':'uc','mark-engine-gateway/.*':'gateway']; //遍历所有修改了的文件 for (file in modifiedFile) { for(entry in patternMap.entrySet()){ if (file ==~ entry.key) { buildComponents << entry.value; } } }

根据需要构建的组件,拼接maven构建指令。

String mvnCmd = 'mvn clean install -Dmaven.test.skip=true' for(component in buildComponents){ mvnCmd = mvnCmd + ' -pl mark-engine-'+component+','; }

经过调试和测试push,三个目标全部完成。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsxfjf.html