Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/20 Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Co-committed-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
98 lines
3.4 KiB
Groovy
98 lines
3.4 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']]],
|
|
]
|
|
]
|
|
|
|
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()
|
|
}
|
|
}
|
|
}
|
|
}
|