[DO-103] Add eva link with pr (#13)
Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/13 Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.tech> Reviewed-by: Andrey Danin <andrey.danin@avroid.tech> Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Co-committed-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
This commit is contained in:
committed by
Aleksandr Vodyanov
parent
4a54b6de6b
commit
5d6e266419
60
pipelines/gitea-events/eva-pr-link-webhook.groovy
Normal file
60
pipelines/gitea-events/eva-pr-link-webhook.groovy
Normal file
@@ -0,0 +1,60 @@
|
||||
@Library('shared-lib') _
|
||||
|
||||
import tech.avroid.api.Eva
|
||||
|
||||
properties([
|
||||
buildDiscarder(logRotator(artifactNumToKeepStr: '10',
|
||||
numToKeepStr: '10')),
|
||||
parameters([
|
||||
string(name: 'DATA_JSON', defaultValue: '')
|
||||
])
|
||||
])
|
||||
|
||||
podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"),
|
||||
yaml: """
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
containers:
|
||||
- name: alpine
|
||||
image: ${env.JENKINS_DOCKER_REGISTRY}/docker-hub-proxy/library/alpine:3.18.5
|
||||
command:
|
||||
- sleep
|
||||
args:
|
||||
- 99d
|
||||
resources:
|
||||
limits:
|
||||
cpu: 100m
|
||||
memory: 64Mi
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 64Mi
|
||||
"""
|
||||
) {
|
||||
node(POD_LABEL) {
|
||||
stage('Add PR link to Eva task') {
|
||||
Map dataJSON = readJSON text: params.DATA_JSON
|
||||
String prLink = dataJSON.pull_request.url
|
||||
String taskPattern = '[A-Z]+(-[A-Z]+)?-[0-9]+'
|
||||
// Eva Api adds name with Spaces, but returnes 500 response code
|
||||
String prName = dataJSON.pull_request.title.replace(' ','_')
|
||||
List prTasks = prName.findAll(taskPattern)
|
||||
Eva eva = new Eva(this, env.JENKINS_EVA_URL, env.JENKINS_EVA_CREDENTIALS)
|
||||
|
||||
if (prTasks.isEmpty()) {
|
||||
prTasks = dataJSON.pull_request.body.findAll(taskPattern)
|
||||
}
|
||||
|
||||
prTasks.each { String taskCode ->
|
||||
String taskId = eva.getTaskId(taskCode)
|
||||
|
||||
if (taskId) {
|
||||
eva.createLink(taskId, prName, prLink)
|
||||
println "Eva task $taskCode linked with PR $prLink"
|
||||
} else {
|
||||
println "Eva task $taskCode doesn't exist"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user