Files
jenkins-pipelines/pipelines/gitea-events/jobs-runner.groovy
Rustam Tagaev 2eac82a73c [DO-502] add_vault_restore_policy (!42)
Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech>
Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/42
Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team>
Reviewed-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.team>
2024-11-07 13:04:14 +03:00

110 lines
3.6 KiB
Groovy

@Library('shared-lib') _
properties([
buildDiscarder(logRotator(artifactNumToKeepStr: '10',
numToKeepStr: '10')),
pipelineTriggers(
[GenericTrigger(
causeString: 'Generic Cause',
allowSeveralTriggersPerBuild: false,
genericVariables: [[key: 'jsonEvent', value: '$']],
token: env.JOB_NAME)
]
)
])
Map projects = [
'DevOps/jenkins-pipelines': [
[
'branches': [],
'jobs': [
[job: 'jobs-dsl/jobs-dsl']
]
],
],
'DevOps/ansible': [
[
'branches': [],
'jobs': [
[job: 'Automation/DevOps/vault-policies-and-roles-update']
]
],
]
]
podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"),
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 projectName = fullJSON.repository.full_name
currentBuild.description = "Repo: ${fullJSON.repository.full_name}"
currentBuild.displayName = "#${env.BUILD_ID} Skip"
//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
} finally {
cleanWs()
}
}
}
}