[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
24
jobs-dsl/jobs/gitea_events/eva_pr_link_webhook.groovy
Normal file
24
jobs-dsl/jobs/gitea_events/eva_pr_link_webhook.groovy
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
pipelineJob('gitea-events/eva-pr-link-webhook') {
|
||||||
|
parameters {
|
||||||
|
string {
|
||||||
|
description('Data from webhook JSON')
|
||||||
|
name('DATA_JSON')
|
||||||
|
defaultValue('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
definition {
|
||||||
|
cpsScm {
|
||||||
|
scm {
|
||||||
|
git {
|
||||||
|
remote {
|
||||||
|
url("${JENKINS_GIT_REPOSITORY_URL}/DevOps/jenkins-pipelines.git")
|
||||||
|
credentials("${JENKINS_GIT_CREDENTIALS_HTTP}")
|
||||||
|
}
|
||||||
|
branch('master')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scriptPath('pipelines/gitea-events/eva-pr-link-webhook.groovy')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,55 +20,53 @@ Map projects = [
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
String getBranch(Map fullJSON) {
|
|
||||||
String refHead = 'refs/heads/'
|
|
||||||
String refTags = 'refs/tags/'
|
|
||||||
|
|
||||||
if (fullJSON.ref.contains(refHead)) {
|
|
||||||
return fullJSON.ref.split(refHead).last()
|
|
||||||
}
|
|
||||||
if (fullJSON.ref.contains(refTags)) {
|
|
||||||
return fullJSON.ref.split(refTags).last()
|
|
||||||
}
|
|
||||||
return fullJSON.ref
|
|
||||||
}
|
|
||||||
|
|
||||||
podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"),
|
podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"),
|
||||||
yaml: '''
|
yaml: """
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Pod
|
kind: Pod
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: linux
|
- name: linux
|
||||||
image: harbor.avroid.tech/devops/base-build-image:1.0
|
image: ${env.JENKINS_DOCKER_REGISTRY}/docker-hub-proxy/library/alpine:3.18.5
|
||||||
command:
|
command:
|
||||||
- sleep
|
- sleep
|
||||||
args:
|
args:
|
||||||
- 99d
|
- 99d
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 300m
|
cpu: 100m
|
||||||
memory: 256Mi
|
memory: 64Mi
|
||||||
requests:
|
requests:
|
||||||
cpu: 300m
|
cpu: 100m
|
||||||
memory: 256Mi
|
memory: 64Mi
|
||||||
imagePullSecrets:
|
"""
|
||||||
- name: harbor-registry-secret
|
|
||||||
'''
|
|
||||||
) {
|
) {
|
||||||
node(POD_LABEL) {
|
node(POD_LABEL) {
|
||||||
stage('Run job') {
|
stage('Run job') {
|
||||||
try {
|
try {
|
||||||
Map fullJSON = readJSON text: jsonEvent
|
Map fullJSON = readJSON text: jsonEvent
|
||||||
String branch = getBranch(fullJSON)
|
|
||||||
String projectName = fullJSON.repository.full_name
|
String projectName = fullJSON.repository.full_name
|
||||||
|
currentBuild.description = "Repo: ${fullJSON.repository.full_name}"
|
||||||
println fullJSON //debug
|
|
||||||
currentBuild.description = "Repo: ${fullJSON.repository.full_name} ${branch}"
|
|
||||||
currentBuild.displayName = "#${env.BUILD_ID} Skip"
|
currentBuild.displayName = "#${env.BUILD_ID} Skip"
|
||||||
projects[projectName].each { project ->
|
|
||||||
|
//info for Debug
|
||||||
|
//println(fullJSON)
|
||||||
|
if (fullJSON.ref) {
|
||||||
|
String branch = ''
|
||||||
|
currentBuild.description = "Repo: ${fullJSON.repository.full_name} $branch"
|
||||||
|
String refHead = 'refs/heads/'
|
||||||
|
String refTags = 'refs/tags/'
|
||||||
|
|
||||||
|
if (fullJSON.ref.contains(refHead)) {
|
||||||
|
branch = fullJSON.ref.split(refHead).last()
|
||||||
|
} else {
|
||||||
|
branch = fullJSON.ref.split(refTags).last()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check project in map and start to work with it
|
||||||
|
projects[projectName].each { Map project ->
|
||||||
currentBuild.displayName = "#${env.BUILD_ID} Run for branches"
|
currentBuild.displayName = "#${env.BUILD_ID} Run for branches"
|
||||||
project.jobs.each { job ->
|
project.jobs.each { Map job ->
|
||||||
build job: job.job,
|
build job: job.job,
|
||||||
parameters: [
|
parameters: [
|
||||||
string(name: 'PROJECT_NAME', value: projectName),
|
string(name: 'PROJECT_NAME', value: projectName),
|
||||||
@@ -78,6 +76,17 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"),
|
|||||||
wait: false
|
wait: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start tasks for all repositories by PR
|
||||||
|
if (fullJSON.action == 'opened') {
|
||||||
|
currentBuild.displayName = "#${env.BUILD_ID} run on PR"
|
||||||
|
build job: 'gitea-events/eva-pr-link-webhook',
|
||||||
|
parameters: [
|
||||||
|
string(name: 'DATA_JSON', value: fullJSON.toString())
|
||||||
|
],
|
||||||
|
wait: false
|
||||||
|
}
|
||||||
} catch (groovy.lang.MissingPropertyException e) {
|
} catch (groovy.lang.MissingPropertyException e) {
|
||||||
println 'This job should run through gitea webhook:\n' + e
|
println 'This job should run through gitea webhook:\n' + e
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user