[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:
aleksandr.vodyanov
2024-01-10 17:15:16 +03:00
committed by Aleksandr Vodyanov
parent 4a54b6de6b
commit 5d6e266419
3 changed files with 153 additions and 60 deletions

View File

@@ -20,67 +20,76 @@ 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"),
yaml: '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: linux
image: harbor.avroid.tech/devops/base-build-image:1.0
command:
- sleep
args:
- 99d
resources:
limits:
cpu: 300m
memory: 256Mi
requests:
cpu: 300m
memory: 256Mi
imagePullSecrets:
- name: harbor-registry-secret
'''
yaml: """
apiVersion: v1
kind: Pod
spec:
containers:
- name: linux
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('Run job') {
try {
Map fullJSON = readJSON text: jsonEvent
String branch = getBranch(fullJSON)
String projectName = fullJSON.repository.full_name
node(POD_LABEL) {
stage('Run job') {
try {
Map fullJSON = readJSON text: jsonEvent
String projectName = fullJSON.repository.full_name
currentBuild.description = "Repo: ${fullJSON.repository.full_name}"
currentBuild.displayName = "#${env.BUILD_ID} Skip"
println fullJSON //debug
currentBuild.description = "Repo: ${fullJSON.repository.full_name} ${branch}"
currentBuild.displayName = "#${env.BUILD_ID} Skip"
projects[projectName].each { project ->
currentBuild.displayName = "#${env.BUILD_ID} Run for branches"
project.jobs.each { job ->
build job: job.job,
parameters: [
string(name: 'PROJECT_NAME', value: projectName),
string(name: 'BRANCH_NAME', value: branch),
string(name: 'DATA_JSON', value: fullJSON.toString())
],
wait: false
}
}
} catch (groovy.lang.MissingPropertyException e) {
println 'This job should run through gitea webhook:\n' + e
}
}
}
//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"
project.jobs.each { Map job ->
build job: job.job,
parameters: [
string(name: 'PROJECT_NAME', value: projectName),
string(name: 'BRANCH_NAME', value: branch),
string(name: 'DATA_JSON', value: fullJSON.toString())
],
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) {
println 'This job should run through gitea webhook:\n' + e
}
}
}
}