DO-63/Waydroid_build (#1)
+ Added jobs-dsl and gitea events 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
70e286b008
commit
9046f994f1
85
pipelines/gitea-events/jobs-runner.groovy
Normal file
85
pipelines/gitea-events/jobs-runner.groovy
Normal file
@@ -0,0 +1,85 @@
|
||||
@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']]],
|
||||
]
|
||||
]
|
||||
|
||||
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(yaml: '''
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
containers:
|
||||
- name: linux
|
||||
image: harbor.avroid.tech/tavro/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
|
||||
'''
|
||||
) {
|
||||
node(POD_LABEL) {
|
||||
stage('Run job') {
|
||||
try {
|
||||
Map fullJSON = readJSON text: jsonEvent
|
||||
String branch = getBranch(fullJSON)
|
||||
String projectName = fullJSON.repository.full_name
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user