Webhook Jenkinsdan ma'lumot oladi
Katta jamoada loyiha ustida hamkorlik qilayotganda, loyihadagi yangi yangilanish ishga tayyor yoki yo‘qligini bilish foydali bo‘lishi mumkin. Yangi takomillashtirishlar tayyor bo‘lganida, bunday bildirishni mos Planfix vazifasidagi izoh sifatida dasturchilarga jo‘natish mumkin. Ushbu funksionallikni Jenkins va incoming webhooks yordamida amalga oshirish mumkin.
Qanday qilish kerak
- Quyidagi turdagi commitlarni yarating: 123456 - commit matni, bunda 123456 Planfixdagi vazifa raqami.
- Commitlarni qabul qiluvchi webhook yarating.
- Webhookga ma'lumot yuboruvchi Jenkins Pipeline ichidagi kodni qo‘shing.
Webhook sozlamalari
Jenkinsdagi kod
Ikki yordamchi funksiya:
@NonCPS
def getTaskNumber(text) {
def m = (text =~ /\d+/);
def taskNumber = m ? m[0] : "";
return taskNumber
}
@NonCPS
def getChangesByTaskNumber() {
def changes = [:]
def maxMessages = 50;
def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length && i + j < maxMessages; j++) {
def entry = entries[j]
def taskNumber = getTaskNumber(entry.msg);
if(taskNumber != "") {
if(!changes.containsKey(taskNumber)) {
changes[taskNumber] = "";
}
changes[taskNumber] += entry.msg + "<br>"
}
}
}
return changes
}
Amallar yakunlangandan keyin qo‘yiladigan kod:
def deployedTasks = getChangesByTaskNumber()
deployedTasks.eachWithIndex { key, value, i ->
httpRequest contentType: "APPLICATION_JSON_UTF8", httpMode: "POST", requestBody: "{ \"task\" : ${key}, \"comment\" : \"${value.replaceAll('"','\\\\"')}\", \"project\" : \"project-name\", \"branch\" : \"${env.gitlabBranch}\"}", responseHandle: "NONE", url: "https://myacc.planfix.ru/webhook/json/b7mh-dead-687f-lpwq";, consoleLogResponseBody: true
}
Yakuniy natija
Dasturchi vazifada shunday izohni ko‘radi: